我正在阅读“Scala第3版编程”。当我在本书中运行示例代码时,我失败了。代码如下:
def maxListImpParm[T](elements: List[T])
(implicit ordering: Ordering[T]): T = {
elements match {
case List() => throw new IllegalArgumentException("empty list!")
case List(x) => x
case x :: rest => {
val maxRest = maxListImpParm(rest)(ordering)
if (ordering.gt(x, maxRest)) x else maxRest }
}
}
我得到的错误是:
<console>:38: error: constructor cannot be instantiated to expected type;
found : shapeless.::[H,T]
required: List[?T1] where type ?T1 <: T (this is a GADT skolem)
case x :: rest =>
^
代码与本书中的示例完全相同。谁能告诉我这里发生了什么。感谢