This is a classic ambiguity in "since".Here it's sort of epistemic:If you know how to do a three way comparison on Tthen you must know how to test equality on Ttherefore it is reasonable for anything that implements Ord to implement Eq as welland 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 == EQappears to be legal Haskell. GHC is happy with it and it seems to work._______________________________________________On Mon, 29 Jul 2019 at 03:52, David Fox <dsf@seereason.com> wrote:On page 39 you sayA 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 <cosmiafu@gmail.com> wrote:_______________________________________________Hi everyone,Though some of you might already knows, I'm pleased to announce a new Haskell book,To Kata Haskellen Evangelion.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.