implementation module rwst from Data.Func import $ import Data.Functor import Data.Monoid import Control.Monad import Control.Applicative Start = "Test" :: RWST r w s m a = RWST (r s -> m (a, s, w)) runRWST :: (RWST r w s m a) r s -> m (a, s, w) runRWST (RWST f) r s = f r s instance Functor (RWST r w s m) | Monad m & Monoid w where fmap f m = liftM f m instance Applicative (RWST r w s m) | Monad m & Monoid w where pure a = RWST \_ s->pure (a, s, mempty) (<*>) mf mx = ap mf mx instance Monad (RWST r w s m) | Monad m & Monoid w where bind m k = RWST \r s->runRWST m r s >>= \(a, s`, w)->runRWST (k a) r s` >>= \(b, s``,w`)->pure (b, s``, mappend w w`)