Beyond Liskov: Type Safe Equality in Scala

I’m kind of bummed the == problem wasn’t fixed in a way that didn’t require using def equals at all.

One approach would be that == in scala always looks for an Equiv[A] instance (which is already in the standard library). If you want java .equals(that: Any) use .equals.

By automatically generating Equiv instances (and ordering) for case classes and enums (which I think can be done with deriving), I think the usability is good.

I’m kind of bummed we have this complex two parameter type-class that is only a marker trait, and not really how the function is dispatched… It feels pretty hacky to me, and it would be really nice if we didn’t have to have a hacky solution and could just do the direct and obvious thing.

I guess this means that cats/scalaz === trick which does the above will continue to live on, which is a shame.

6 Likes