[GHC] #10598: DeriveAnyClass and GND don't work well together
GHC
ghc-devs at haskell.org
Fri Jul 3 00:33:25 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:
-------------------------------------+-------------------------------------
Description changed by osa1:
Old description:
> 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.
New description:
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.
--
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10598#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list