{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE Safe #-}
#endif
#if __GLASGOW_HASKELL__ >= 710
{-# LANGUAGE AutoDeriveTypeable #-}
#endif
module Control.Monad.Trans.RWS.Lazy (
RWS,
rws,
runRWS,
evalRWS,
execRWS,
mapRWS,
withRWS,
RWST(..),
evalRWST,
execRWST,
mapRWST,
withRWST,
reader,
ask,
local,
asks,
writer,
tell,
listen,
listens,
pass,
censor,
state,
get,
put,
modify,
gets,
liftCallCC,
liftCallCC',
liftCatch,
) where
import Control.Monad.IO.Class
import Control.Monad.Signatures
import Control.Monad.Trans.Class
#if MIN_VERSION_base(4,12,0)
import Data.Functor.Contravariant
#endif
import Data.Functor.Identity
import Control.Applicative
import Control.Monad
#if MIN_VERSION_base(4,9,0)
import qualified Control.Monad.Fail as Fail
#endif
import Control.Monad.Fix
import Data.Monoid
type RWS r w s = RWST r w s Identity
rws :: (r -> s -> (a, s, w)) -> RWS r w s a
rws :: (r -> s -> (a, s, w)) -> RWS r w s a
rws r -> s -> (a, s, w)
f = (r -> s -> Identity (a, s, w)) -> RWS r w s a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST (\ r
r s
s -> (a, s, w) -> Identity (a, s, w)
forall a. a -> Identity a
Identity (r -> s -> (a, s, w)
f r
r s
s))
{-# INLINE rws #-}
runRWS :: RWS r w s a -> r -> s -> (a, s, w)
runRWS :: RWS r w s a -> r -> s -> (a, s, w)
runRWS RWS r w s a
m r
r s
s = Identity (a, s, w) -> (a, s, w)
forall a. Identity a -> a
runIdentity (RWS r w s a -> r -> s -> Identity (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWS r w s a
m r
r s
s)
{-# INLINE runRWS #-}
evalRWS :: RWS r w s a
-> r
-> s
-> (a, w)
evalRWS :: RWS r w s a -> r -> s -> (a, w)
evalRWS RWS r w s a
m r
r s
s = let
(a
a, s
_, w
w) = RWS r w s a -> r -> s -> (a, s, w)
forall r w s a. RWS r w s a -> r -> s -> (a, s, w)
runRWS RWS r w s a
m r
r s
s
in (a
a, w
w)
{-# INLINE evalRWS #-}
execRWS :: RWS r w s a
-> r
-> s
-> (s, w)
execRWS :: RWS r w s a -> r -> s -> (s, w)
execRWS RWS r w s a
m r
r s
s = let
(a
_, s
s', w
w) = RWS r w s a -> r -> s -> (a, s, w)
forall r w s a. RWS r w s a -> r -> s -> (a, s, w)
runRWS RWS r w s a
m r
r s
s
in (s
s', w
w)
{-# INLINE execRWS #-}
mapRWS :: ((a, s, w) -> (b, s, w')) -> RWS r w s a -> RWS r w' s b
mapRWS :: ((a, s, w) -> (b, s, w')) -> RWS r w s a -> RWS r w' s b
mapRWS (a, s, w) -> (b, s, w')
f = (Identity (a, s, w) -> Identity (b, s, w'))
-> RWS r w s a -> RWS r w' s b
forall (m :: * -> *) a s w (n :: * -> *) b w' r.
(m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b
mapRWST ((b, s, w') -> Identity (b, s, w')
forall a. a -> Identity a
Identity ((b, s, w') -> Identity (b, s, w'))
-> (Identity (a, s, w) -> (b, s, w'))
-> Identity (a, s, w)
-> Identity (b, s, w')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, s, w) -> (b, s, w')
f ((a, s, w) -> (b, s, w'))
-> (Identity (a, s, w) -> (a, s, w))
-> Identity (a, s, w)
-> (b, s, w')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identity (a, s, w) -> (a, s, w)
forall a. Identity a -> a
runIdentity)
{-# INLINE mapRWS #-}
withRWS :: (r' -> s -> (r, s)) -> RWS r w s a -> RWS r' w s a
withRWS :: (r' -> s -> (r, s)) -> RWS r w s a -> RWS r' w s a
withRWS = (r' -> s -> (r, s)) -> RWS r w s a -> RWS r' w s a
forall r' s r w (m :: * -> *) a.
(r' -> s -> (r, s)) -> RWST r w s m a -> RWST r' w s m a
withRWST
{-# INLINE withRWS #-}
newtype RWST r w s m a = RWST { RWST r w s m a -> r -> s -> m (a, s, w)
runRWST :: r -> s -> m (a, s, w) }
evalRWST :: (Monad m)
=> RWST r w s m a
-> r
-> s
-> m (a, w)
evalRWST :: RWST r w s m a -> r -> s -> m (a, w)
evalRWST RWST r w s m a
m r
r s
s = do
~(a
a, s
_, w
w) <- RWST r w s m a -> r -> s -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m a
m r
r s
s
(a, w) -> m (a, w)
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, w
w)
{-# INLINE evalRWST #-}
execRWST :: (Monad m)
=> RWST r w s m a
-> r
-> s
-> m (s, w)
execRWST :: RWST r w s m a -> r -> s -> m (s, w)
execRWST RWST r w s m a
m r
r s
s = do
~(a
_, s
s', w
w) <- RWST r w s m a -> r -> s -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m a
m r
r s
s
(s, w) -> m (s, w)
forall (m :: * -> *) a. Monad m => a -> m a
return (s
s', w
w)
{-# INLINE execRWST #-}
mapRWST :: (m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b
mapRWST :: (m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b
mapRWST m (a, s, w) -> n (b, s, w')
f RWST r w s m a
m = (r -> s -> n (b, s, w')) -> RWST r w' s n b
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> n (b, s, w')) -> RWST r w' s n b)
-> (r -> s -> n (b, s, w')) -> RWST r w' s n b
forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> m (a, s, w) -> n (b, s, w')
f (RWST r w s m a -> r -> s -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m a
m r
r s
s)
{-# INLINE mapRWST #-}
withRWST :: (r' -> s -> (r, s)) -> RWST r w s m a -> RWST r' w s m a
withRWST :: (r' -> s -> (r, s)) -> RWST r w s m a -> RWST r' w s m a
withRWST r' -> s -> (r, s)
f RWST r w s m a
m = (r' -> s -> m (a, s, w)) -> RWST r' w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r' -> s -> m (a, s, w)) -> RWST r' w s m a)
-> (r' -> s -> m (a, s, w)) -> RWST r' w s m a
forall a b. (a -> b) -> a -> b
$ \ r'
r s
s -> (r -> s -> m (a, s, w)) -> (r, s) -> m (a, s, w)
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (RWST r w s m a -> r -> s -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m a
m) (r' -> s -> (r, s)
f r'
r s
s)
{-# INLINE withRWST #-}
instance (Functor m) => Functor (RWST r w s m) where
fmap :: (a -> b) -> RWST r w s m a -> RWST r w s m b
fmap a -> b
f RWST r w s m a
m = (r -> s -> m (b, s, w)) -> RWST r w s m b
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (b, s, w)) -> RWST r w s m b)
-> (r -> s -> m (b, s, w)) -> RWST r w s m b
forall a b. (a -> b) -> a -> b
$ \ r
r s
s ->
((a, s, w) -> (b, s, w)) -> m (a, s, w) -> m (b, s, w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\ ~(a
a, s
s', w
w) -> (a -> b
f a
a, s
s', w
w)) (m (a, s, w) -> m (b, s, w)) -> m (a, s, w) -> m (b, s, w)
forall a b. (a -> b) -> a -> b
$ RWST r w s m a -> r -> s -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m a
m r
r s
s
{-# INLINE fmap #-}
instance (Monoid w, Functor m, Monad m) => Applicative (RWST r w s m) where
pure :: a -> RWST r w s m a
pure a
a = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
_ s
s -> (a, s, w) -> m (a, s, w)
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, s
s, w
forall a. Monoid a => a
mempty)
{-# INLINE pure #-}
RWST r -> s -> m (a -> b, s, w)
mf <*> :: RWST r w s m (a -> b) -> RWST r w s m a -> RWST r w s m b
<*> RWST r -> s -> m (a, s, w)
mx = (r -> s -> m (b, s, w)) -> RWST r w s m b
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (b, s, w)) -> RWST r w s m b)
-> (r -> s -> m (b, s, w)) -> RWST r w s m b
forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> do
~(a -> b
f, s
s', w
w) <- r -> s -> m (a -> b, s, w)
mf r
r s
s
~(a
x, s
s'',w
w') <- r -> s -> m (a, s, w)
mx r
r s
s'
(b, s, w) -> m (b, s, w)
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b
f a
x, s
s'', w
w w -> w -> w
forall a. Monoid a => a -> a -> a
`mappend` w
w')
{-# INLINE (<*>) #-}
instance (Monoid w, Functor m, MonadPlus m) => Alternative (RWST r w s m) where
empty :: RWST r w s m a
empty = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
_ s
_ -> m (a, s, w)
forall (m :: * -> *) a. MonadPlus m => m a
mzero
{-# INLINE empty #-}
RWST r -> s -> m (a, s, w)
m <|> :: RWST r w s m a -> RWST r w s m a -> RWST r w s m a
<|> RWST r -> s -> m (a, s, w)
n = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> r -> s -> m (a, s, w)
m r
r s
s m (a, s, w) -> m (a, s, w) -> m (a, s, w)
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` r -> s -> m (a, s, w)
n r
r s
s
{-# INLINE (<|>) #-}
instance (Monoid w, Monad m) => Monad (RWST r w s m) where
#if !(MIN_VERSION_base(4,8,0))
return a = RWST $ \ _ s -> return (a, s, mempty)
{-# INLINE return #-}
#endif
RWST r w s m a
m >>= :: RWST r w s m a -> (a -> RWST r w s m b) -> RWST r w s m b
>>= a -> RWST r w s m b
k = (r -> s -> m (b, s, w)) -> RWST r w s m b
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (b, s, w)) -> RWST r w s m b)
-> (r -> s -> m (b, s, w)) -> RWST r w s m b
forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> do
~(a
a, s
s', w
w) <- RWST r w s m a -> r -> s -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m a
m r
r s
s
~(b
b, s
s'',w
w') <- RWST r w s m b -> r -> s -> m (b, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST (a -> RWST r w s m b
k a
a) r
r s
s'
(b, s, w) -> m (b, s, w)
forall (m :: * -> *) a. Monad m => a -> m a
return (b
b, s
s'', w
w w -> w -> w
forall a. Monoid a => a -> a -> a
`mappend` w
w')
{-# INLINE (>>=) #-}
#if !(MIN_VERSION_base(4,13,0))
fail msg = RWST $ \ _ _ -> fail msg
{-# INLINE fail #-}
#endif
#if MIN_VERSION_base(4,9,0)
instance (Monoid w, Fail.MonadFail m) => Fail.MonadFail (RWST r w s m) where
fail :: String -> RWST r w s m a
fail String
msg = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
_ s
_ -> String -> m (a, s, w)
forall (m :: * -> *) a. MonadFail m => String -> m a
Fail.fail String
msg
{-# INLINE fail #-}
#endif
instance (Monoid w, MonadPlus m) => MonadPlus (RWST r w s m) where
mzero :: RWST r w s m a
mzero = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
_ s
_ -> m (a, s, w)
forall (m :: * -> *) a. MonadPlus m => m a
mzero
{-# INLINE mzero #-}
RWST r -> s -> m (a, s, w)
m mplus :: RWST r w s m a -> RWST r w s m a -> RWST r w s m a
`mplus` RWST r -> s -> m (a, s, w)
n = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> r -> s -> m (a, s, w)
m r
r s
s m (a, s, w) -> m (a, s, w) -> m (a, s, w)
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` r -> s -> m (a, s, w)
n r
r s
s
{-# INLINE mplus #-}
instance (Monoid w, MonadFix m) => MonadFix (RWST r w s m) where
mfix :: (a -> RWST r w s m a) -> RWST r w s m a
mfix a -> RWST r w s m a
f = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> ((a, s, w) -> m (a, s, w)) -> m (a, s, w)
forall (m :: * -> *) a. MonadFix m => (a -> m a) -> m a
mfix (((a, s, w) -> m (a, s, w)) -> m (a, s, w))
-> ((a, s, w) -> m (a, s, w)) -> m (a, s, w)
forall a b. (a -> b) -> a -> b
$ \ ~(a
a, s
_, w
_) -> RWST r w s m a -> r -> s -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST (a -> RWST r w s m a
f a
a) r
r s
s
{-# INLINE mfix #-}
instance (Monoid w) => MonadTrans (RWST r w s) where
lift :: m a -> RWST r w s m a
lift m a
m = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
_ s
s -> do
a
a <- m a
m
(a, s, w) -> m (a, s, w)
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, s
s, w
forall a. Monoid a => a
mempty)
{-# INLINE lift #-}
instance (Monoid w, MonadIO m) => MonadIO (RWST r w s m) where
liftIO :: IO a -> RWST r w s m a
liftIO = m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RWST r w s m a) -> (IO a -> m a) -> IO a -> RWST r w s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
{-# INLINE liftIO #-}
#if MIN_VERSION_base(4,12,0)
instance Contravariant m => Contravariant (RWST r w s m) where
contramap :: (a -> b) -> RWST r w s m b -> RWST r w s m a
contramap a -> b
f RWST r w s m b
m = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \r
r s
s ->
((a, s, w) -> (b, s, w)) -> m (b, s, w) -> m (a, s, w)
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
contramap (\ ~(a
a, s
s', w
w) -> (a -> b
f a
a, s
s', w
w)) (m (b, s, w) -> m (a, s, w)) -> m (b, s, w) -> m (a, s, w)
forall a b. (a -> b) -> a -> b
$ RWST r w s m b -> r -> s -> m (b, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m b
m r
r s
s
{-# INLINE contramap #-}
#endif
reader :: (Monoid w, Monad m) => (r -> a) -> RWST r w s m a
reader :: (r -> a) -> RWST r w s m a
reader = (r -> a) -> RWST r w s m a
forall w (m :: * -> *) r a s.
(Monoid w, Monad m) =>
(r -> a) -> RWST r w s m a
asks
{-# INLINE reader #-}
ask :: (Monoid w, Monad m) => RWST r w s m r
ask :: RWST r w s m r
ask = (r -> s -> m (r, s, w)) -> RWST r w s m r
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (r, s, w)) -> RWST r w s m r)
-> (r -> s -> m (r, s, w)) -> RWST r w s m r
forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> (r, s, w) -> m (r, s, w)
forall (m :: * -> *) a. Monad m => a -> m a
return (r
r, s
s, w
forall a. Monoid a => a
mempty)
{-# INLINE ask #-}
local :: (r -> r) -> RWST r w s m a -> RWST r w s m a
local :: (r -> r) -> RWST r w s m a -> RWST r w s m a
local r -> r
f RWST r w s m a
m = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> RWST r w s m a -> r -> s -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m a
m (r -> r
f r
r) s
s
{-# INLINE local #-}
asks :: (Monoid w, Monad m) => (r -> a) -> RWST r w s m a
asks :: (r -> a) -> RWST r w s m a
asks r -> a
f = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> (a, s, w) -> m (a, s, w)
forall (m :: * -> *) a. Monad m => a -> m a
return (r -> a
f r
r, s
s, w
forall a. Monoid a => a
mempty)
{-# INLINE asks #-}
writer :: (Monad m) => (a, w) -> RWST r w s m a
writer :: (a, w) -> RWST r w s m a
writer (a
a, w
w) = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
_ s
s -> (a, s, w) -> m (a, s, w)
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, s
s, w
w)
{-# INLINE writer #-}
tell :: (Monad m) => w -> RWST r w s m ()
tell :: w -> RWST r w s m ()
tell w
w = (r -> s -> m ((), s, w)) -> RWST r w s m ()
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m ((), s, w)) -> RWST r w s m ())
-> (r -> s -> m ((), s, w)) -> RWST r w s m ()
forall a b. (a -> b) -> a -> b
$ \ r
_ s
s -> ((), s, w) -> m ((), s, w)
forall (m :: * -> *) a. Monad m => a -> m a
return ((),s
s,w
w)
{-# INLINE tell #-}
listen :: (Monad m) => RWST r w s m a -> RWST r w s m (a, w)
listen :: RWST r w s m a -> RWST r w s m (a, w)
listen RWST r w s m a
m = (r -> s -> m ((a, w), s, w)) -> RWST r w s m (a, w)
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m ((a, w), s, w)) -> RWST r w s m (a, w))
-> (r -> s -> m ((a, w), s, w)) -> RWST r w s m (a, w)
forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> do
~(a
a, s
s', w
w) <- RWST r w s m a -> r -> s -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m a
m r
r s
s
((a, w), s, w) -> m ((a, w), s, w)
forall (m :: * -> *) a. Monad m => a -> m a
return ((a
a, w
w), s
s', w
w)
{-# INLINE listen #-}
listens :: (Monad m) => (w -> b) -> RWST r w s m a -> RWST r w s m (a, b)
listens :: (w -> b) -> RWST r w s m a -> RWST r w s m (a, b)
listens w -> b
f RWST r w s m a
m = (r -> s -> m ((a, b), s, w)) -> RWST r w s m (a, b)
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m ((a, b), s, w)) -> RWST r w s m (a, b))
-> (r -> s -> m ((a, b), s, w)) -> RWST r w s m (a, b)
forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> do
~(a
a, s
s', w
w) <- RWST r w s m a -> r -> s -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m a
m r
r s
s
((a, b), s, w) -> m ((a, b), s, w)
forall (m :: * -> *) a. Monad m => a -> m a
return ((a
a, w -> b
f w
w), s
s', w
w)
{-# INLINE listens #-}
pass :: (Monad m) => RWST r w s m (a, w -> w) -> RWST r w s m a
pass :: RWST r w s m (a, w -> w) -> RWST r w s m a
pass RWST r w s m (a, w -> w)
m = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> do
~((a
a, w -> w
f), s
s', w
w) <- RWST r w s m (a, w -> w) -> r -> s -> m ((a, w -> w), s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m (a, w -> w)
m r
r s
s
(a, s, w) -> m (a, s, w)
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, s
s', w -> w
f w
w)
{-# INLINE pass #-}
censor :: (Monad m) => (w -> w) -> RWST r w s m a -> RWST r w s m a
censor :: (w -> w) -> RWST r w s m a -> RWST r w s m a
censor w -> w
f RWST r w s m a
m = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> do
~(a
a, s
s', w
w) <- RWST r w s m a -> r -> s -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m a
m r
r s
s
(a, s, w) -> m (a, s, w)
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, s
s', w -> w
f w
w)
{-# INLINE censor #-}
state :: (Monoid w, Monad m) => (s -> (a,s)) -> RWST r w s m a
state :: (s -> (a, s)) -> RWST r w s m a
state s -> (a, s)
f = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
_ s
s -> let (a
a,s
s') = s -> (a, s)
f s
s in (a, s, w) -> m (a, s, w)
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, s
s', w
forall a. Monoid a => a
mempty)
{-# INLINE state #-}
get :: (Monoid w, Monad m) => RWST r w s m s
get :: RWST r w s m s
get = (r -> s -> m (s, s, w)) -> RWST r w s m s
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (s, s, w)) -> RWST r w s m s)
-> (r -> s -> m (s, s, w)) -> RWST r w s m s
forall a b. (a -> b) -> a -> b
$ \ r
_ s
s -> (s, s, w) -> m (s, s, w)
forall (m :: * -> *) a. Monad m => a -> m a
return (s
s, s
s, w
forall a. Monoid a => a
mempty)
{-# INLINE get #-}
put :: (Monoid w, Monad m) => s -> RWST r w s m ()
put :: s -> RWST r w s m ()
put s
s = (r -> s -> m ((), s, w)) -> RWST r w s m ()
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m ((), s, w)) -> RWST r w s m ())
-> (r -> s -> m ((), s, w)) -> RWST r w s m ()
forall a b. (a -> b) -> a -> b
$ \ r
_ s
_ -> ((), s, w) -> m ((), s, w)
forall (m :: * -> *) a. Monad m => a -> m a
return ((), s
s, w
forall a. Monoid a => a
mempty)
{-# INLINE put #-}
modify :: (Monoid w, Monad m) => (s -> s) -> RWST r w s m ()
modify :: (s -> s) -> RWST r w s m ()
modify s -> s
f = (r -> s -> m ((), s, w)) -> RWST r w s m ()
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m ((), s, w)) -> RWST r w s m ())
-> (r -> s -> m ((), s, w)) -> RWST r w s m ()
forall a b. (a -> b) -> a -> b
$ \ r
_ s
s -> ((), s, w) -> m ((), s, w)
forall (m :: * -> *) a. Monad m => a -> m a
return ((), s -> s
f s
s, w
forall a. Monoid a => a
mempty)
{-# INLINE modify #-}
gets :: (Monoid w, Monad m) => (s -> a) -> RWST r w s m a
gets :: (s -> a) -> RWST r w s m a
gets s -> a
f = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
_ s
s -> (a, s, w) -> m (a, s, w)
forall (m :: * -> *) a. Monad m => a -> m a
return (s -> a
f s
s, s
s, w
forall a. Monoid a => a
mempty)
{-# INLINE gets #-}
liftCallCC :: (Monoid w) =>
CallCC m (a,s,w) (b,s,w) -> CallCC (RWST r w s m) a b
liftCallCC :: CallCC m (a, s, w) (b, s, w) -> CallCC (RWST r w s m) a b
liftCallCC CallCC m (a, s, w) (b, s, w)
callCC (a -> RWST r w s m b) -> RWST r w s m a
f = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s ->
CallCC m (a, s, w) (b, s, w)
callCC CallCC m (a, s, w) (b, s, w) -> CallCC m (a, s, w) (b, s, w)
forall a b. (a -> b) -> a -> b
$ \ (a, s, w) -> m (b, s, w)
c ->
RWST r w s m a -> r -> s -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST ((a -> RWST r w s m b) -> RWST r w s m a
f (\ a
a -> (r -> s -> m (b, s, w)) -> RWST r w s m b
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (b, s, w)) -> RWST r w s m b)
-> (r -> s -> m (b, s, w)) -> RWST r w s m b
forall a b. (a -> b) -> a -> b
$ \ r
_ s
_ -> (a, s, w) -> m (b, s, w)
c (a
a, s
s, w
forall a. Monoid a => a
mempty))) r
r s
s
{-# INLINE liftCallCC #-}
liftCallCC' :: (Monoid w) =>
CallCC m (a,s,w) (b,s,w) -> CallCC (RWST r w s m) a b
liftCallCC' :: CallCC m (a, s, w) (b, s, w) -> CallCC (RWST r w s m) a b
liftCallCC' CallCC m (a, s, w) (b, s, w)
callCC (a -> RWST r w s m b) -> RWST r w s m a
f = (r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s ->
CallCC m (a, s, w) (b, s, w)
callCC CallCC m (a, s, w) (b, s, w) -> CallCC m (a, s, w) (b, s, w)
forall a b. (a -> b) -> a -> b
$ \ (a, s, w) -> m (b, s, w)
c ->
RWST r w s m a -> r -> s -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST ((a -> RWST r w s m b) -> RWST r w s m a
f (\ a
a -> (r -> s -> m (b, s, w)) -> RWST r w s m b
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (b, s, w)) -> RWST r w s m b)
-> (r -> s -> m (b, s, w)) -> RWST r w s m b
forall a b. (a -> b) -> a -> b
$ \ r
_ s
s' -> (a, s, w) -> m (b, s, w)
c (a
a, s
s', w
forall a. Monoid a => a
mempty))) r
r s
s
{-# INLINE liftCallCC' #-}
liftCatch :: Catch e m (a,s,w) -> Catch e (RWST r w s m) a
liftCatch :: Catch e m (a, s, w) -> Catch e (RWST r w s m) a
liftCatch Catch e m (a, s, w)
catchE RWST r w s m a
m e -> RWST r w s m a
h =
(r -> s -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> RWST r w s m a -> r -> s -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m a
m r
r s
s Catch e m (a, s, w)
`catchE` \ e
e -> RWST r w s m a -> r -> s -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST (e -> RWST r w s m a
h e
e) r
r s
s
{-# INLINE liftCatch #-}