X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=RWST.icl;h=2f02d6dce1dbd86d5e32d9a1ded2a46a137044bf;hb=74b900cf6db033a51e177f7f85d835dae44217e5;hp=712f71e62db2689d3824e473b2705f3540ac566c;hpb=13a108705dbabbc75711ce9b3b29fe508262919f;p=cc1516.git diff --git a/RWST.icl b/RWST.icl index 712f71e..2f02d6d 100644 --- a/RWST.icl +++ b/RWST.icl @@ -8,6 +8,7 @@ import Data.Functor.Identity import Data.Functor import Data.Monoid import Control.Monad +import Control.Monad.Trans import Control.Applicative // The RWS monad @@ -46,6 +47,9 @@ instance Monad (RWST r w s m) | Monad m & Monoid w where >>= \(a, s`, w)->runRWST (k a) r s` >>= \(b, s``,w`)->pure (b, s``, mappend w w`) +instance MonadTrans (RWST r w s) | Monoid w where + liftT m = RWST \_ s->m >>= \a->pure (a, s, mempty) + runRWST :: (RWST r w s m a) r s -> m (a, s, w) runRWST (RWST f) r s = f r s