I have the following newtype
:
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
newtype Wrap m a = Wrap {runWrap :: m a}
deriving (Functor, Applicative, Monad, MonadTrans)
I'm trying to derive MonadTrans
automatically, but I get the following error:
• Can't make a derived instance of ‘MonadTrans Wrap’
(even with cunning GeneralizedNewtypeDeriving):
cannot eta-reduce the representation type enough
• In the newtype declaration for ‘Wrap’
However, writing the trivial instance for MonadTrans
works just fine:
instance MonadTrans Wrap where
lift = Wrap
What is the reason for such an error message?
GeneralizedNewtypeDeriving
uses the underlying instance for a class for the implementation of the class for the newtype
. However, in this case that doesn't make any sense, because m
isn't of the right kind to even be an instance of MonadTrans
(recall that m :: * -> *
, but MonadTrans
wants (* -> *) -> * -> *
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With