[Haskell-cafe] Derivation of Eq given Ord
Andreas Marth
Andreas-Haskell at gmx.net
Thu Aug 9 12:26:30 EDT 2007
I would say that qualifies as a bug because it relays an error from compile
time to run time.
Andreas
----- Original Message -----
From: "Dougal Stanton" <ithika at gmail.com>
To: "haskell-cafe" <haskell-cafe at haskell.org>
Sent: Thursday, August 09, 2007 5:57 PM
Subject: [Haskell-cafe] Derivation of Eq given Ord
> 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.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list