Why can the Price not find the attribute value on the SeqValue? It seems so simple that is should work.
Im getting the error
[error] .... value value is not a member of type parameter SeqValue
[error] def recalc[SeqValue](input:SeqValue) = Price(1 + seq, input.value)
for the following code
sealed trait SeqValue {
def seq:Int
def value:Float
override def toString = ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE)
}
sealed trait Calc {
type S <: SeqValue
def recalc[S](input:S):SeqValue
}
case class Price(seq:Int=0, value:Float=.0f) extends SeqValue with Calc {
def recalc[SeqValue](input:SeqValue) = Price(1 + seq, input.value)
}
The idea is that you can recalc on the price object, and pass in any type of object that implements SeqValue, because SeqValue has a value.
S = SeqValue
in every class – Digit