创建<;:<-类似于Scala中的隐式自定义继承结构

创建<;:<-类似于Scala中的隐式自定义继承结构,scala,implicit,implicits,Scala,Implicit,Implicits,我有一个密封的实体特征,可以是根或后代[p sealed trait Entity class Root extends Entity class Descendant[P <: Entity] extends Entity sealed trait <#<[From, To] def check[F <: Entity, T <: Entity](implicit ev: F <#< T): Unit = {} object TRoot exte

我有一个密封的
实体
特征,可以是
后代[p
sealed trait Entity
class Root extends Entity
class Descendant[P <: Entity] extends Entity

sealed trait <#<[From, To]

def check[F <: Entity, T <: Entity](implicit ev: F <#< T): Unit = {}
object TRoot extends Root
object TBase extends Descendant[TRoot.type]
object TSub extends Descendant[TBase.type]

check[TRoot.type, TRoot.type]
check[TBase.type, TRoot.type]
check[TSub.type, TRoot.type]
trait Descendant[P <: Entity] { type Parent = P }

// In some parent object, so it will have lower priority
def childConforms[T <: Entity, D <: Descendant[_, _]](implicit ev: D#Parent <#< T):
          (D <#< T) = // create instance, e.g. from singleton

// In child object with higher priority than `childConforms`
def selfConforms[T <: Entity): (T <#< T) = // ...
def selfConforms[T <: Entity]: (T <#< T) = ...
def child1Conforms[T <: Entity, D <: Descendant[T]]: (D <#< T) = ...
def child2Conforms[T <: Entity, D <: Descendant[Descendant[T]]]: (D <#< T) = ...
// and so on