trait Operable {
def +[A](other: A)(implicit evidence: this.type =:= A): this.type
def -[A](other: A)(implicit evidence: this.type =:= A): this.type
def *[A](other: Float): this.type
}
/** Position descriptions */
trait Pos[T <: Operable] {
def eval: T
}
def test[T <: Operable](x1: Pos[T], x2: Pos[T]): T = {
x2.eval - x1.eval
}
而且我得到以下编译时错误:
Cannot prove that _1.type =:= T.
为什么不能编译器证明式的平等,以及如何克服这个问题?来自x1和x2的T参数应该是相同的。为什么不是这样?
我想雷吉斯给你(使用F-界多态性)的答案是要走的路,但值得一提的是,编译器会很乐意与'< :<而不是'=:='。 – Hugh