I have the class Variable[X <: SeqVal[_]](initialState:Calc[X])
which I instantiate with new Variable[SeqVal[Float]](Max()) where Max is
case class Max(seq: Int = 0, value: Float = .0f) extends SeqVal[Float] with Calc[SeqVal[Float]], and there are other case classes other than Max.
This does not compile even though Max does implement a variant of the trait Calc[SeqVal[_]].
[error] ../Variable.scala:14: type mismatch;
[error] found : com.quasiquant.calc.Max
[error] required: com.quasiquant.calc.Calc[com.quasiquant.calc.Price]
[error] Note: com.quasiquant.messages.SeqVal[Float] >: com.quasiquant.calc.Price (and com.quasiquant.calc.Max <: com.quasiquant.calc.Calc[com.quasiquant.messages.SeqVal[Float]]), but trait Calc is invariant in type X.
[error] You may wish to define X as -X instead. (SLS 4.5)
[error] extends Variable[Price](Max(), initChildren)
I need help in trying to work out how I can change the bounding of initialState:Calc[X] so the initialState can be set to anything that implements Calc[X] (not just Max). I would prefer it if i didn’t have to add a second type parameter to all the instantiations of Variable
Here’s the code I tried compiling:
Compiles without errors.