Ticket #1608 (closed bug: fixed)

Opened 6 years ago

Last modified 5 years ago

Newtype deriving error messages coming out too late

Reported by: simonpj Owned by: simonpj
Priority: normal Milestone: 6.10 branch
Component: Compiler (Type checker) Version: 6.6.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: drvfail012 Blocked By:
Blocking: Related Tickets:

Description

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

Change History

Changed 6 years ago by simonpj

  • status changed from new to closed
  • testcase set to drvfail012
  • resolution set to fixed

And indeed this is just what GHC (6.8 and HEAD) now does:

Der.hs:3:0:
    No instance for (Eq (Ego a))
      arising from the 'deriving' clause of a data type declaration
		   at Der.hs:3:0-35
    Possible fix: add an instance declaration for (Eq (Ego a))
    When deriving the instance for (Ord (Ego a))

So it's fixed, with no merging to be done. I've added a test case to the test suite though.

Changed 5 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

Changed 5 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple
Note: See TracTickets for help on using tickets.