[Haskell-cafe] (names for) invariants for Eq and Ord?

Johannes Waldmann johannes.waldmann at htwk-leipzig.de
Mon May 28 14:47:27 UTC 2018


Dear Cafe,

I am somewhat surprised that the Haskell Standard (*)
https://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1270006.3
does not contain any
notation for (intended) properties of Eq and Ord instances,
and their relation. For Java (standard library),
the API spec uses wording like "consistent with equals"
https://docs.oracle.com/javase/10/docs/api/java/lang/Comparable.html

I am well aware that semantics (transitivity, etc.)
cannot be enforced statically, in either language.
But both standards still speak of "total order".
Do we (Haskell) need something similar to "consistent with equals"?

It depends. E.g., looking at a (random) source in containers
(Data.Map.Internal), it seems that it will always use the result of
compare, never of (==), on keys. That's not obvious from the docs.
I just checked -- I can make a type where (==) = undefined,
but write a proper Ord instance, and use it as key type.

I am asking this because I will be teaching type classes,
with Eq and Ord as examples. I detected the funny situation
that the Java specification looks "more mathematical"
than the corresponding Haskell one. What will the students think ...

- J.W.

(*) The Haskell standard is what you find when you scroll
down, down, down to the very bottom of
https://www.haskell.org/documentation . So, probably not that important...


More information about the Haskell-Cafe mailing list