I'm trying to write a generic interpolate
method that works on any type that has two methods, a *
and a +
, like this:
trait Container {
type V = {
def *(t: Double): V
def +(v: V): V
}
def interpolate(t: Double, a: V, b: V): V = a * (1.0 - t) + b * t
}
This doesn't work though (on Scala 2.8.0.RC7), I get the following error messages:
<console>:8: error: recursive method + needs result type
def +(v: V): V
^
<console>:7: error: recursive method * needs result type
def *(t: Double): V
^
How do I specify the structural type correctly? (Or is there a better way to do this?)