
But it's hard to specify the "constraint" / completeness condition (see the
MINIMAL pragma) of "can be fully expressed via constructors". Note also
that this doesn't work for numbers: you can use constructor syntax, but
it's desugared to (==). So it's inviting confusion in a number of ways,
including some that don't matter directly (you're unlikely to write your
own Ord instance for numbers like that) but matter for understanding how
the language fits together, which is already confused by e.g. above "sugar".
On Tue, Jul 30, 2019 at 8:23 AM Richard O'Keefe
This is a classic ambiguity in "since". Here it's sort of epistemic: If you know how to do a three way comparison on T then you must know how to test equality on T therefore it is reasonable for anything that implements Ord to implement Eq as well and it would confuse people a lot if <= and >= were allowed but not == so Haskell requires instances of Ord to also be instances of Eq.
You are right:
data T = A | B
instance Ord T where compare A A = EQ compare A B = LT compare B A = GT compare B B = EQ
instance Eq T where x == y = compare x y == EQ
appears to be legal Haskell. GHC is happy with it and it seems to work.
On Mon, 29 Jul 2019 at 03:52, David Fox
wrote: On page 39 you say
A type can have Ord instance only when it has Eq instance, since if
you want to compare items, you need a way to test if they are equal.
So from my reading of this you are saying that an Eq instance for a type needs to be supplied before we are allowed to implement compare. However it is easy to write a compare function that makes no use of the underlying (==) function. Indeed, once you have done this you can turn around and write a == b = compare a b == EQ. So I was wondering if you could clarify the role of constraints in the class declaration.
On Sun, Jul 28, 2019 at 2:38 AM Cosmia Fu
wrote: Hi everyone,
Though some of you might already knows, I'm pleased to announce a new Haskell book, *To Kata Haskellen Evangelion*. Link: https://cosmius.bitbucket.io/tkhe/ I believe that it does not have to be hard to learn Haskell.
I begun to write the book in 2017 December, and... to be honest, I don't know what to write now, though I still think it incomplete. It will probably not be updated for quite a while. So I decide to announce it earlier.
I am not a native English speaker, so it might be not fluent or even with a lot of grammar mistakes. It would be very nice of you if you can tell me the mistakes in it, factual, technical or grammar. And also feel free to tell me if you want to read some topic in it.
Thank you
----
Cosmia Fu _______________________________________________ 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.
_______________________________________________ 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.
_______________________________________________ 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 allbery.b@gmail.com