[Haskell-cafe] Typeclass resolution errors quite puzzling

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Mon Aug 15 13:35:15 UTC 2016


On Mon, Aug 15, 2016 at 03:33:23PM +0200, Damian Nadales wrote:
> On Mon, Aug 15, 2016 at 3:26 PM, Tom Ellis
> <tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk> wrote:
> > Here's a program with an odd error message (GHC 8.0.1):
> >
> >     data A a = A a deriving Eq
> >     data B = B
> >
> >     main :: IO ()
> >     main = print (A B == A B)
> >
> >     test/main.hs:5:15: error:
> >         • No instance for (Eq B) arising from a use of ‘==’
> >         • In the first argument of ‘print’, namely ‘(A B == A B)’
> >           In the expression: print (A B == A B)
> >           In an equation for ‘main’: main = print (A B == A B)
>
> I would expect this error, since B does not implement equality. Maybe
> you're expecting Haskell to automatically derive an Eq B instance, but
> that is not the behavior I would want, since data definitions could
> implicitly define instances for other data types.
> 
> Is there any reason why you don't define:
>   data B = B deriving Eq?

My complaint is about the confusing error message, not the failure to
type check.


More information about the Haskell-Cafe mailing list