Request for feedback: deriving strategies syntax
ryan.gl.scott at gmail.com
Sun Jul 17 20:17:33 UTC 2016
> When the deriving strategies extension isn't enabled , what will the new semantics be when more than one strategy applies? What's our new answer there ?
GHC already has a process for resolving which strategy to pick in a
plain old deriving statement, but it isn't well documented. I've added
a section to the users' guide in , but I'll summarize it here.
When processing a deriving statement without an explicit strategy:
1. If the typeclass is built-in (or wired-in, as you suggested), and
any necessary language extension is enabled (e.g., -XDeriveFunctor for
Functor), then GHC will use the corresponding built-in algorithm to
derive the instance.
2. Otherwise, GHC checks if either -XGeneralizedNewtypeDeriving or
-XDeriveAnyClass are enabled, and if the class is able to be derived
with one of those approaches, GHC does so. If BOTH extensions are
enabled and the class can be derived with either approach, GHC
defaults to -XDeriveAnyClass (but also emitting a warning about the
choice it made to resolve the ambiguity).
3. Otherwise, GHC errors.
Again, this is current GHC behavior, not a new or proposed feature.
More information about the ghc-devs