concept GeneralizedNewtypeDeriving in category haskell

This is an excerpt from Manning's book Haskell in Depth.
The
runAppfield is the monad stack itself. The deriving clause generates all the functionality required. Deriving is implemented by theGeneralizedNewtypeDerivingGHC extension, it must be enabled to compile this code. The idea behind it is rather simple. For example, to provide thetellmethod for theMyApp smonad the deriving machinery generates a method body with something likelift . tell(one level down along the monad stack to get to theWritermonad). The method body forgetbecomeslift . lift . getto reach theStatemonad. We’ll discuss other details on instance deriving later in this book.
Note that the
GeneralizedNewtypeDerivingGHC extension fails to generate instances if there are no appropriateCoercibleinstances around. The whole roles andCoercibleidea have arisen from the following bug in the older GHC versions. Suppose we have the following type family: