[Haskell-cafe] Derivation of Eq given Ord

Dougal Stanton ithika at gmail.com
Thu Aug 9 11:57:26 EDT 2007


Is there a reason why automatic derivation of Ord without Eq doesn't
do "the sensible thing" and just derive Eq anyway?

> newtype Id a = Id { a :: String }
>                    deriving (Read, Show, Eq, Ord)
> newtype Ego a = Ego { b :: String }
>                    deriving (Read, Show, Ord)

Both will type check, but if you try any (in)equality operators on the
second they'll be spat back at you.

> *Main> let e1 = Ego ""
> *Main> let e2 = Ego ""
> *Main> e1 < e2
>
> <interactive>:1:0:
>     No instance for (Eq (Ego a))
>       arising from use of `<' at <interactive>:1:0-6
>     Possible fix: add an instance declaration for (Eq (Ego a))
>     In the expression: e1 < e2
>     In the definition of `it': it = e1 < e2

It doesn't seem *much* of a hardship, but it wasn't what I expected.
I'm not used to GHC accepting input and silently dropping stuff it
doesn't like...

Cheers,

D.


More information about the Haskell-Cafe mailing list