3
我有以下newtype
:不能使單子轉換的派生實例
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
newtype Wrap m a = Wrap {runWrap :: m a}
deriving (Functor, Applicative, Monad, MonadTrans)
我試圖自動獲得MonadTrans
,但我得到了以下錯誤:
• 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’
然而,寫作MonadTrans
的微不足道實例工作得很好:
instance MonadTrans Wrap where
lift = Wrap
這種錯誤信息的原因是什麼?
在這種情況下,「一類的底層實例」是什麼意思? –
有沒有一種方法來派生'MonadTrans'的微不足道的實例? –
差不多一年後[看來我一直在打同一面牆](https://stackoverflow.com/questions/47579216/doing-dependency-injection-using-monad-stacks)。 –