module Control.Monad.Trans.MSF.RWS
( module Control.Monad.Trans.MSF.RWS
, module Control.Monad.Trans.RWS.Strict
) where
import Control.Monad.Trans.RWS.Strict
hiding (liftCallCC, liftCatch)
import Data.Monoid
import Data.Functor ((<$>))
import Control.Monad.Trans.MSF.GenLift
import Data.MonadicStreamFunction
runRWSS :: (Monad m, Monoid w)
=> MSF (RWST r w s m) a b
-> MSF m (r, s, a) (w, s, b)
runRWSS = transS transformInput transformOutput
where
transformInput (_, _, a) = return a
transformOutput (r, s, _) msfaction = sym <$> runRWST msfaction r s
sym ((b, msf'), s, w) = ((w, s, b), msf')
rwsS :: (Monad m, Monoid w)
=> MSF m (r, s, a) (w, s, b)
-> MSF (RWST r w s m) a b
rwsS = lifterS wrapRWST
where
wrapRWST :: Monad m
=> ((r, s, a) -> m ((w, s, b), c)) -> a -> RWST r w s m (b, c)
wrapRWST f a = RWST $ \r s -> do
((w, s', b), c) <- f (r, s, a)
return ((b, c), s', w)