6
Haskell中可以推導出實例MonadState s
以下但不T1
在T2
然而,這是一個非常相似的類型。在哪種方式下,我應該修改T2
的代碼,以便MonadState s
的實例可以自動派生?廣義NEWTYPE派生
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import Control.Monad.Reader
import Control.Monad.State
newtype T1 r s a =
T1 { runT1 :: ReaderT r (State s) a }
deriving (Monad, MonadReader r, MonadState s)
newtype T2 r s a =
T2 { runT2 :: StateT r (State s) a }
deriving (Monad, MonadState r, MonadState s)