Ticket #1588 (closed bug: fixed)

Opened 6 years ago

Last modified 5 years ago

unrequested generalized newtype deriving?

Reported by: SamB Owned by: igloo
Priority: normal Milestone: 6.8.1
Component: Compiler Version: 6.6.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: drvfail013 Blocked By:
Blocking: Related Tickets:

Description

Consider the two type definitions:

newtype MaybeT  m a = MaybeT  { runMaybeT  :: m (Maybe a) } deriving Eq
data    MaybeT' m a = MaybeT' { runMaybeT' :: m (Maybe a) } deriving Eq

Why is it that the former compiles, with no flags of any kind, but the latter does not? It seems like generalized newtype deriving is happening when unrequested and undesired...

(I'm trying to figure out how Derive should derive Eq, and compiler bugs don't help much ;-)

Change History

Changed 6 years ago by Isaac Dupree

  • version changed from 6.6 to 6.6.1

Hugs gives

ERROR "t.hs":3 - Illegal Haskell 98 class constraint in derived instance
*** Instance   : Eq (MaybeT a b)
*** Constraint : Eq (a (Maybe b))

Which is much clearer (to me at least) than ghc's

t.hs:4:8:
    No instance for (Eq (m (Maybe a)))
      arising from the 'deriving' clause of a data type declaration
      at t.hs:4:8
    Possible fix: add an instance declaration for (Eq (m (Maybe a)))
    When deriving the instance for `Eq (MaybeT' m a)'

That is to say, Hugs refuses even the first one, as well as the second one. Your problem is that GHC is treating newtypes differently from data (neither of which fall within Haskell98 in this case). (I have no idea if this is a bug. It happens on 6.6.1 at least.)

Changed 6 years ago by SamB

Yes. Refusing both was the expected behaviour -- sorry if I didn't make that clear. I didn't ask for any extensions.

Changed 6 years ago by igloo

  • owner set to igloo
  • milestone set to 6.8.1

Thanks for the report; these both give me:

   No instance for (Eq (m (Maybe a)))
      arising from the 'deriving' clause of a data type declaration
                   at z.hs:2:0-70
    Possible fix: add an instance declaration for (Eq (m (Maybe a)))
    When deriving the instance for (Eq (MaybeT m a))

with GHC 6.8.1. I'll add your testcase to the testsuite.

Changed 6 years ago by simonpj

Right. That is, you'll add a test case and close the bug, right. Because GHC 6.8 and the HEAD are behaving as Sam expects.

Simon

Changed 6 years ago by igloo

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

Exactly; now done.

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.