[GHC] #10598: DeriveAnyClass and GND don't work well together

GHC ghc-devs at haskell.org
Tue Apr 5 18:01:57 UTC 2016


#10598: DeriveAnyClass and GND don't work well together
-------------------------------------+-------------------------------------
        Reporter:  osa1              |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.2.1
       Component:  Compiler          |              Version:  7.11
      Resolution:                    |             Keywords:  Generics
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by bgamari):

 * milestone:   => 8.2.1


@@ -5,1 +5,1 @@
- {{{
+ {{{#!hs

New description:

 I think we definitely have a bug here, but I'm not sure what it really is.

 Here's the program:

 {{{#!hs
 newtype MyMaybe a = MyMaybe (Maybe a)
   deriving (Functor, Show)

 main = print $ MyMaybe $ Just (10 :: Int)
 }}}

 I'm using GHC 7.10.1.

 {{{
 ➜  deriveany_bug  ghc --make -fforce-recomp Test.hs -XDeriveAnyClass
 -XGeneralizedNewtypeDeriving
 [1 of 1] Compiling Main             ( Test.hs, Test.o )

 Test.hs:2:13:
     Can't make a derived instance of ‘Functor MyMaybe’
       (even with cunning newtype deriving):
       You need DeriveFunctor to derive an instance for this class
       Try GeneralizedNewtypeDeriving for GHC's newtype-deriving extension
     In the newtype declaration for ‘MyMaybe’
 }}}

 Just to try, changing argument order:

 {{{
 ➜  deriveany_bug  ghc --make -fforce-recomp Test.hs
 -XGeneralizedNewtypeDeriving -XDeriveAnyClass
 [1 of 1] Compiling Main             ( Test.hs, Test.o )

 Test.hs:2:13:
     Can't make a derived instance of ‘Functor MyMaybe’
       (even with cunning newtype deriving):
       You need DeriveFunctor to derive an instance for this class
       Try GeneralizedNewtypeDeriving for GHC's newtype-deriving extension
     In the newtype declaration for ‘MyMaybe’
 }}}

 It works fine if I remove `DeriveAnyClass`:

 {{{
 ➜  deriveany_bug  ghc --make -fforce-recomp Test.hs
 -XGeneralizedNewtypeDeriving
 [1 of 1] Compiling Main             ( Test.hs, Test.o )
 Linking Test ...
 }}}

 GHC HEAD is failing in exactly the same way.

 User manual is saying this in 7.5.6:

 > In case you try to derive some class on a newtype, and
 -XGeneralizedNewtypeDeriving is also on, -XDeriveAnyClass takes
 precedence.

 But then why is it telling me to enable `GeneralizedNewtypeDeriving` in
 the error message? Even if I already enabled it?

 Also, maybe it could try `GND` when `DeriveAnyClass` fails? Because the
 doc is saying `DeriveAnyClass` has precedence but doesn't specify what
 happens if it fails.

 EDIT: I'd like to work on this myself if experts here help me figuring the
 right behavior here.

--

Comment:

 I think we should really try to fix this for 8.2. Currently
 `DeriveAnyClass` is nearly useless as in most cases I'd much rather give
 it up than `GeneralizedNewtypeDeriving`.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10598#comment:21>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list