하스켈은 MonadState s
의 인스턴스를 T1
에 파생시킬 수 있지만 T2
은 매우 비슷합니다. MonadState s
에 대한 인스턴스가 자동으로 파생 될 수 있도록 어떤 식으로 T2
의 코드를 수정해야합니까?일반화 된 Newtype Deriving
{-# 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)