In Scala I can enforce type equality at compile time. For example:
case class Foo[A,B]( a: A, b: B )( implicit ev: A =:= B )
scala> Foo( 1, 2 )
res3: Foo[Int,Int] = Foo(1,2)
scala> Foo( 1, "2" )
<console>:10: error: Cannot prove that Int =:= java.lang.String.
Is there a way to enforce that type A and type B should be different ?
Riffing off of Jean-Philippe’s ideas, this works:
Then:
I’d probably simplify this as follows, since the checks for “cheating” can always be circumvented anyway (e.g.
Foo(1, 1)(null)or=!=.nequal(null)):