I am writing a form function
def test[A,B](a: A, b: B)(implicit eq: A =:= B): Unit = ...
where I need confirmation that types A and B same.
I would expect the calls of the form test(a,a) to compile for any A , but it does not seem to be the case when type A includes existences, for example, in
case class Foo[T](c: T) val l = List(Foo(1), Foo(1.0F), Foo(0.0)) // Inferred type: List[Foo[_ >: Double with Float with Int <: AnyVal]] test(l.head, l.head) // Does not compile, error like: Cannot prove that Foo[_7] =:= Foo[_7].
So my question is: am I using =:= incorrectly? Or could it be a mistake? Or a fundamental limitation of existentiality? Or a restriction on their implementation?
Context
I am testing the return type of a function f with dependent types. I expect it to return the same type for A and B in val a = f(...); val b = f(...) val a = f(...); val b = f(...) , so I call test(a, b) . If types A and B include existences, even test(a,a) and test(b,b) not compiled as described above.
source share