Hacker News new | ask | show | jobs
by eru 3624 days ago
Just define your own equality operator?

Eg in Haskell, whether things can be compared for equality depends on their representation. (Eg church encoded datatypes do not lent themselves to the built-in derivation of the == operator.)

2 comments

If you can't use the builtin `==` operator, you can throw away much of the builtin functionality. The runtime uses `==` in far too many places without ability to provide your own comparator. You want to use your own types as keys in a `Map` or `WeakMap`? Yeah, not going to work.
> Just define your own equality operator?

Have fun doing that in JavaScript. Have fun making objects/hashtables use your custom equality operator when comparing field names. Have fun making sure that every single part of your program respects the notion of equality defined by your custom equality operator.

> Eg in Haskell, whether things can be compared for equality depends on their representation.

In any higher-order langauge, that's a feature, not a bug.