【发布时间】:2015-06-02 18:12:32
【问题描述】:
我有以下案例类:
case class <*>[Q <: Quantity[T], R <: Quantity[T], T](value: T)
extends Quantity[T]
我想这样使用它:
type Area[T] = Length[T] <*> Length[T]
但是,我收到一条错误消息,指出 <*> 需要三个参数,而我只给出了两个。我希望它像这样工作:
type Area[T] = <*>[Length[T], Length[T], T]
我尝试了以下方法,但它给了我一个错误:
trait Quantity[T] {
type Value = T
def value: T
}
case class <*>[Q <: Quantity[_],
R <: Quantity[_]](value: Q#Value)
(implicit eq: Q#Value =:= R#Value)
extends Quantity[Q#Value]
错误:(13, 110) 非法继承;
自类型<*>[Q,R]不符合Quantity[_$1]的自类型Quantity[_$1]case class <*>[Q <: Quantity[_], R <: Quantity[_]](value: Q#Value) (implicit eq: Q#Value =:= R#Value) extends Quantity[Q#Value] ^
有解决办法吗?如有必要,我不介意重命名案例类,尽管我确实想要漂亮的中缀语法。
【问题讨论】:
-
@Kigyo 它不会编译。类型 T 仍然未知
-
@wedens 你是对的。我一定在 repl 中输入了不同的内容。谢谢。
-
我知道这是一个老问题,但不是第一个 Quantity[_] 和第二个被视为不同类型的问题(在“不同范围内使用相同的占位符名称 _$1 “)?我想我曾经有过这样的经历。