Skip to content

Newtype deriving error messages coming out too late

Consider this

newtype Ego a = Ego a deriving (Ord)

f :: Ord a => Ego a -> Ego a -> Bool
f e1 e2 = e1 < e2

GHC 6.7 reports an error like this:

    Could not deduce (Eq (Ego a)) from the context (Ord a)
      arising from a use of `<' at Foo10.hs:6:10-16
    In the expression: e1 < e2
    In the definition of `f': f e1 e2 = e1 < e2

This error should have come when you gave the instance decl. The reason is that GHC's newtype deriving is generating an instance like

instance Eq (Ego a) => Ord (Ego a)

It would make more sense to report the missing instance for Eq right there, rather than abstracting over it.

Thanks to Dougal Stanton for pointing this out: http://www.haskell.org/pipermail/haskell-cafe/2007-August/030224.html

Trac metadata
Trac field Value
Version 6.6.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system Unknown
Architecture Unknown
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information