[Haskell-cafe] (names for) invariants for Eq and Ord?
Brandon Allbery
allbery.b at gmail.com
Tue May 29 19:24:28 UTC 2018
One thing to consider is that, if you look at the Report specification for
derived Ord instances and of the default (compare), you'll find that it
explicitly depends on (==). So you don't actually need a "law" here.
On Tue, May 29, 2018 at 3:03 PM Johannes Waldmann <
johannes.waldmann at htwk-leipzig.de> wrote:
> 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...
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
--
brandon s allbery kf8nh sine nomine associates
allbery.b at gmail.com ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180529/d39738d9/attachment.html>
More information about the Haskell-Cafe
mailing list