[GHC] #10598: DeriveAnyClass and GND don't work well together
GHC
ghc-devs at haskell.org
Wed Jul 22 21:24:37 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:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions:
-------------------------------------+-------------------------------------
Comment (by oerjan):
Hm so here is my "ideal" made-up-on-the-spot system. It somewhat combines
all of 2, 3 and 4 from
https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/GenericDeriving#InteractionwithGeneralizedNewtypeDeriving.
It is intended to be backwards-compatible, except for one added warning.
* By 3, classes may be annotated (pragma?) to say they prefer GND or DAC
deriving. Builtin-derived classes count as annotated for their own style
of deriving. To actually derive a class in a module, any extension for the
derivation style still needs to be enabled as well.
* By 4, if `GeneralizedNewtypeDeriving` is enabled, the `newtype` keyword
may be used to signify that an instance for a newtype should be GND
derived, even if this is against the annotated behavior for the class.
This might even include builtin-derived classes like `Show`. (Obviously
not `Typeable`, though.)
* Also by 4, if both `GeneralizedNewtypeDeriving` and `DeriveAnyClass` are
enabled (or for least surprise, maybe even with just the latter), the
`default` keyword may be used to signify that an instance for a newtype
should ''not'' be GND-derived, even if this is the annotated behavior for
the class.
* By 2, if ''neither'' the newtype deriving nor the class is annotated,
then the behavior depends on which of `GeneralizedNewtypeDeriving` and
`DeriveAnyClass` is enabled. If ''both'' are enabled, then a ''warning''
should be given. (This prevents surprises when a user adds both extensions
for unrelated instances.) Then it defaults to DAC as today.
* Although the proper extensions need to be enabled for whichever
annotations/derivation styles end up being used, the ''only'' case where
simply changing the extensions enabled will change code from one legal
style of derivation to another should be the one in the previous point.
(And thus the warning.)
As of now, I don't remember any classes with builtin-derivations that also
are useful with `DeriveAnyClass`. So I think there isn't much need to be
able to distinguish those two cases. Which also means that none of this
matters to `data` declarations, only `newtype`.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10598#comment:19>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list