DeriveAnyClass and GND don't work well together
I think we definitely have a bug here, but I'm not sure what it really is.
Here's the program:
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.