Scala Type Equivalence Checking on Singleton Types

70 Views Asked by At

I have a function to witness type equivalence:

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

It fails to check the following two different singleton types:

class X
val a = new X; val b = new X
val aa:a.type = a; val bb:b.type = b
typeEq(aa, bb)

However, if I write this way, the compiler works fine:

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)
         ^

Appreciate your help.

0

There are 0 best solutions below