[Haskell-cafe] ANN: To Kata Haskellen Evangelion

Richard O'Keefe raoknz at gmail.com
Tue Jul 30 12:22:54 UTC 2019


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 <dsf at seereason.com> 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 <cosmiafu at 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*.
>> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20190731/4ab3a8cd/attachment.html>


More information about the Haskell-Cafe mailing list