I would like to be able to provide a copy-on-update function in a parametrized, F-Bounded trait, where the value to B updated is also F-Bounded. The traits are as follows:
sealed trait A[AA <: A[AA]] {
self: AA =>
val data: String
}
sealed trait B[BB <: B[BB, AA], AA <: A[AA]] {
self: BB =>
val content: AA
}
case class BInst[BB <: B[BB,AA], AA <: A[AA]](content: AA) extends
B[BInst[BB, AA], AA]
In trait B, I would like to provide a function with the signature
def update[NewA <: AA](newA: NewA) : BB[BB, NewA]
so that the case class just implements
def update[NewA <: AA](newA: NewA) = copy(content = newA)
but this doesn't currently compile. What are the correct types for update
in B
?
edit
An example which should work (but currently doesn't):
class A2Inst extends A[A2Inst] { val data: String = "A2Inst" }
class A2Inst2 extends A2Inst {override val data: String = "A2INst2" }
val a1 = new A2Inst
val a2 = new A2Inst2
val b = BInst(a1)
b.update(a2)