I have three F-Bound types A
, B
& C
, where B
is parametrized by A
, and C
is parametrized by B
(and hence also by A
). I can instantiate A
and B
, but when I try to instantiate C
, the compiler is unable to infer the types. If I give it the types explicitly, everything works - but it seems rather silly that these types are lost (is this due to type erasure?).
sealed trait A[AA <: A[AA]] {
self =>
val data: String
}
case class AInst(data: String) extends A[AInst]
sealed trait B[BB <: B[BB, AA], AA <: A[AA]] {
self: BB =>
val content: AA
}
case class BInst[AA <: A[AA]](content: AA) extends B[BInst[AA], AA]
sealed trait C[CC <: C[CC, BB, AA], BB <: B[BB, AA], AA <: A[AA]] {
self: CC =>
val content: BB
}
case class CInst[BB <: B[BB, AA], AA <: A[AA]](content: BB)
extends C[CInst[BB, AA], BB, AA]
val a1 = new AInst("A1")
val b1 = BInst(a1)
val c1 = CInst[BInst[AInst],AInst](b1)
Is there a work around, where I do not have to specify the types for CInst
specifically?
I am currently using type parametrization to implement the F-Bounds, but would switching to abstract type members solve this problem? How would the class look like then?