Generalized newtype deriving
When you define a type using the
you are defining a new type
X is representationally equivalent to
Y, but nominally different; although
Y have the same representation, they are different types. This means that they can have different typeclass instances.
Often, however, you want some (or all) of the typeclass instances for a newtype to be exactly the same as the instances of the underlying type. The
GeneralizedNewtypeDeriving GHC documentation for
GeneralizedNewtypeDeriving. GHC extension provides a convenient way to do that.
As of GHC release 8.6.1 GHC 8.6.1 release notes, you can now spell this extension
GeneralisedNewtypeDeriving if you prefer. We will stick with the American spelling in this article.