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

GHC ghc-devs at haskell.org
Thu Jul 9 21:28:59 UTC 2015


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

Comment (by osa1):

 Sorry for late response, I'm hoping to make progress on this,

 I was wondering if we can use a fallback mechanism in instance deriving.
 For example: If GND and DeriveAnyClass are enabled, we know DeriveAnyClass
 is tried first, but why not try GND when it fails?

 There are couple of things that are very inconvenient with the current
 approach:

 1. If I want to derive two instances for my newtype, one needs GND and one
 needs DeriveAnyClass, I can't do that and I have to split things into
 modules which means orphan instances.

 2. I'm tired of adding dozens of LANGUAGE pragmas in every single file, so
 I was hoping to move those to cabal file. But I can't do that easily
 because of problems like this.

 About the error message: What would be the correct message here? Also,
 even with just `DeriveAnyClass`, the error message is weird:

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

 Test.hs:2:13:
     Can't make a derived instance of ‘Functor MyMaybe’:
       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 first says that I need DeriveFunctor, but then says I should try GND.
 Is it trying to say that GND implies DeriveFunctor? (which shouldn't be
 the case according to the user manual) Otherwise which one should I try?
 This message is confusing IMO.

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


More information about the ghc-tickets mailing list