以下代码取自Apocalisp的优秀博客系列: scala中的类型级编程,并针对隐式解析方案进行了修改.但是,这不会编译,并显示以下消息:
error: ambiguous implicit values:
both method hParseNil in object HApplyOps of type => (com.mystuff.bigdata.commons.collections.hlist.HNil) => com.mystuff.bigdata.commons.collections.hlist.HNil
and method conforms in object Predef of type [A]<:<[A,A]
match expected type (com.mystuff.bigdata.commons.collections.hlist.HNil) => com.amadesa.bigdata.commons.collections.hlist.HNil
val l = hparse[HNil,HNil](HNil)
Run Code Online (Sandbox Code Playgroud)
有人可以解释为什么会发生这种情况,以及它是否可以修复?
sealed trait HList
final case class HCons[H, T <: HList](head: H, tail: T) extends HList {
def :+:[T](v: T) = HCons(v, this)
}
sealed class HNil extends HList {
def :+:[T](v: T) = HCons(v, this)
}
object HNil extends HNil
// …Run Code Online (Sandbox Code Playgroud) scala ×1