私はFバウンドタイプを持っています:
sealed trait A[AA <: A[AA]] {
self: AA =>
}
そして、最初のタイプによってパラメータ化された 2 番目の F-Bound タイプ。
sealed trait B[BB <: B[BB, AA], AA <: A[AA]] {
self: BB =>
val content: AA
}
これらの型を利用するケース クラスを喜んで書くことができます。
case class BInst[BB <: BInst[BB, AA], AA <: A[AA]](content: AA)
extends B[BInst[BB, AA], AA]
ここで、ケース クラスのコンパニオン オブジェクトが必要です。これは、特性 B を通じて参照できます。たとえば、次のようになります。
sealed trait A[AA <: A[AA]] { self: AA => }
sealed trait B[BB <: B[BB, AA], AA <: A[AA]] {
self: BB =>
val content: AA
def companion: Companion[BB]
}
case class BInst[BB <: BInst[BB, AA], AA <: A[AA]](content: AA)
extends B[BInst[BB, AA], AA] {
def companion: Companion[BInst[BB, AA]] = BInst
}
sealed trait Companion[+BB <: B[_, _]]
object BInst extends Companion[BInst]
しかし、コンパニオン パラメーター化 (最後の行) の BInst には型パラメーターが必要なため、これはコンパイルに失敗します。同様に
sealed trait Companion[BB[X, Y] <: B[X, Y]]
失敗します。コンパニオン オブジェクトの正しい型は何ですか?