次のように、 aと ainterpolate
の 2 つのメソッドを持つ任意の型で機能するジェネリック メソッドを作成しようとしています。*
+
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
}
これは機能しませんが (Scala 2.8.0.RC7 では)、次のエラー メッセージが表示されます。
<console>:8: error: recursive method + needs result type
def +(v: V): V
^
<console>:7: error: recursive method * needs result type
def *(t: Double): V
^
構造型を正しく指定するにはどうすればよいですか? (または、これを行うより良い方法はありますか?)