我有一个见证类型等效的功能:
def typeEq[A, B](a: A, b: B)(implicit ev: A =:= B) = println("happy")
typeEq: [A, B](a: A, b: B)(implicit ev: A =:= B)Unit
无法检查以下两种不同的单例类型:
class X
val a = new X; val b = new X
val aa:a.type = a; val bb:b.type = b
typeEq(aa, bb)
但是,如果我这样写,则编译器可以正常工作:
class X
val a = new X; val b = new X
type atype=a.type; type btype=b.type
val aa:atype = a; val bb:btype = b
typeEq(aa, bb)
<console>:15: error: Cannot prove that atype =:= btype.
typeEq(aa, bb)
^
感谢您的帮助。