It just makes sense that =:=
should be commutative: A =:= B
implies B =:= A
. I was wondering if there is a way to make the scala understand this. To elaborate, if I provide the scala with
implicit def typeEqCommutes[A,B](ev: A=:=B): B=:=A = ev.asInstanceOf[B=:=A]then is there a way so the following would compile:
class Pair[T, S](var first: T, var second: S) {
def swap(implicit ev: T =:= S) {
val temp = first
first = second //error: type mismatch; found: S required: T
second = temp
}
}