concrete functor and monad transformers
#84Add composition of MonadTransformers
Add
-- ComposeT :: MonadTransformer -> MonadTransformer -> MonadTransformer
type ComposeT :: (k3 -> k2 -> Type) -> (k1 -> k3) -> (k1 -> k2 -> Type)
newtype ComposeT trans1 trans2 m a = ComposeT (trans1 (trans2 m) a)
deriving newtype (Functor, Applicative, Monad)
instance (MonadTrans trans1, MonadTrans trans2) => MonadTrans (ComposeT trans1 trans2) where
lift :: Monad m => m ~> ComposeT trans1 trans2 m
lift = ComposeT . lift . lift
where MonadTransformer = (Type -> Type) -> (Type -> Type)
.
Now we can derive MonadTrans
for transformers like
type OkT :: MonadTransformer
newtype OkT m a = OkT (Int -> Int -> m a)
deriving (Functor, Applicative, Monad)
via ReaderT Int (ReaderT Int m)
deriving MonadTrans
via ComposeT (ReaderT Int) (ReaderT Int)