{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE Safe #-}
{-# LANGUAGE DeriveGeneric #-}
#endif
#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802
{-# LANGUAGE AutoDeriveTypeable #-}
#endif
module Control.Monad.Trans.RWS.CPS (
RWS,
rws,
runRWS,
evalRWS,
execRWS,
mapRWS,
withRWS,
RWST,
rwsT,
runRWST,
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.Applicative
import Control.Monad
import Control.Monad.Fix
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Control.Monad.Signatures
import Data.Functor.Identity
#if !(MIN_VERSION_base(4,8,0))
import Data.Monoid
#endif
#if MIN_VERSION_base(4,9,0)
import qualified Control.Monad.Fail as Fail
#endif
#if __GLASGOW_HASKELL__ >= 704
import GHC.Generics
#endif
type RWS r w s = RWST r w s Identity
rws :: (Monoid w) => (r -> s -> (a, s, w)) -> RWS r w s a
rws :: forall w r s a. Monoid w => (r -> s -> (a, s, w)) -> RWS r w s a
rws r -> s -> (a, s, w)
f = (r -> s -> w -> Identity (a, s, w)) -> RWST r w s Identity a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> Identity (a, s, w)) -> RWST r w s Identity a)
-> (r -> s -> w -> Identity (a, s, w)) -> RWST r w s Identity a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w ->
let (a
a, s
s', w
w') = r -> s -> (a, s, w)
f r
r s
s; wt :: w
wt = w
w w -> w -> w
forall a. Monoid a => a -> a -> a
`mappend` w
w' in w
wt w -> Identity (a, s, w) -> Identity (a, s, w)
forall a b. a -> b -> b
`seq` (a, s, w) -> Identity (a, s, w)
forall a. a -> Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, s
s', w
wt)
{-# INLINE rws #-}
runRWS :: (Monoid w) => RWS r w s a -> r -> s -> (a, s, w)
runRWS :: forall w r s a. Monoid w => 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 w r s (m :: * -> *) a.
Monoid w =>
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 :: (Monoid w)
=> RWS r w s a
-> r
-> s
-> (a, w)
evalRWS :: forall w r s a. Monoid w => 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 w r s a. Monoid w => 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 :: (Monoid w)
=> RWS r w s a
-> r
-> s
-> (s, w)
execRWS :: forall w r s a. Monoid w => 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 w r s a. Monoid w => 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 :: (Monoid w, Monoid w') => ((a, s, w) -> (b, s, w')) -> RWS r w s a -> RWS r w' s b
mapRWS :: forall w w' a s b r.
(Monoid w, Monoid w') =>
((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'))
-> RWST r w s Identity a -> RWST r w' s Identity b
forall (n :: * -> *) w w' (m :: * -> *) a s b r.
(Monad n, Monoid w, Monoid w') =>
(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 :: forall r' s r w a.
(r' -> s -> (r, s)) -> RWS r w s a -> RWS r' w s a
withRWS = (r' -> s -> (r, s))
-> RWST r w s Identity a -> RWST r' w s Identity 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 { forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> w -> m (a, s, w)
unRWST :: r -> s -> w -> m (a, s, w) }
#if __GLASGOW_HASKELL__ >= 704
deriving ((forall x. RWST r w s m a -> Rep (RWST r w s m a) x)
-> (forall x. Rep (RWST r w s m a) x -> RWST r w s m a)
-> Generic (RWST r w s m a)
forall x. Rep (RWST r w s m a) x -> RWST r w s m a
forall x. RWST r w s m a -> Rep (RWST r w s m a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall r w s (m :: * -> *) a x.
Rep (RWST r w s m a) x -> RWST r w s m a
forall r w s (m :: * -> *) a x.
RWST r w s m a -> Rep (RWST r w s m a) x
$cfrom :: forall r w s (m :: * -> *) a x.
RWST r w s m a -> Rep (RWST r w s m a) x
from :: forall x. RWST r w s m a -> Rep (RWST r w s m a) x
$cto :: forall r w s (m :: * -> *) a x.
Rep (RWST r w s m a) x -> RWST r w s m a
to :: forall x. Rep (RWST r w s m a) x -> RWST r w s m a
Generic)
#endif
rwsT :: (Functor m, Monoid w) => (r -> s -> m (a, s, w)) -> RWST r w s m a
rwsT :: forall (m :: * -> *) w r s a.
(Functor m, Monoid w) =>
(r -> s -> m (a, s, w)) -> RWST r w s m a
rwsT r -> s -> m (a, s, w)
f = (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w ->
(\ (a
a, s
s', w
w') -> let wt :: w
wt = w
w w -> w -> w
forall a. Monoid a => a -> a -> a
`mappend` w
w' in w
wt w -> (a, s, w) -> (a, s, w)
forall a b. a -> b -> b
`seq` (a
a, s
s', w
wt)) ((a, s, w) -> (a, s, w)) -> m (a, s, w) -> m (a, s, w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> r -> s -> m (a, s, w)
f r
r s
s
{-# INLINE rwsT #-}
runRWST :: (Monoid w) => RWST r w s m a -> r -> s -> m (a, s, w)
runRWST :: forall w r s (m :: * -> *) a.
Monoid w =>
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m a
m r
r s
s = RWST r w s m a -> r -> s -> w -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> w -> m (a, s, w)
unRWST RWST r w s m a
m r
r s
s w
forall a. Monoid a => a
mempty
{-# INLINE runRWST #-}
evalRWST :: (Monad m, Monoid w)
=> RWST r w s m a
-> r
-> s
-> m (a, w)
evalRWST :: forall (m :: * -> *) w r s a.
(Monad m, Monoid w) =>
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 w r s (m :: * -> *) a.
Monoid w =>
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 a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, w
w)
{-# INLINE evalRWST #-}
execRWST :: (Monad m, Monoid w)
=> RWST r w s m a
-> r
-> s
-> m (s, w)
execRWST :: forall (m :: * -> *) w r s a.
(Monad m, Monoid w) =>
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 w r s (m :: * -> *) a.
Monoid w =>
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 a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (s
s', w
w)
{-# INLINE execRWST #-}
mapRWST :: (Monad n, Monoid w, Monoid w') =>
(m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b
mapRWST :: forall (n :: * -> *) w w' (m :: * -> *) a s b r.
(Monad n, Monoid w, Monoid w') =>
(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 -> w' -> n (b, s, w')) -> RWST r w' s n b
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w' -> n (b, s, w')) -> RWST r w' s n b)
-> (r -> s -> w' -> n (b, s, w')) -> RWST r w' s n b
forall a b. (a -> b) -> a -> b
$ \ r
r s
s w'
w -> do
(b
a, s
s', w'
w') <- m (a, s, w) -> n (b, s, w')
f (RWST r w s m a -> r -> s -> m (a, s, w)
forall w r s (m :: * -> *) a.
Monoid w =>
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m a
m r
r s
s)
let wt :: w'
wt = w'
w w' -> w' -> w'
forall a. Monoid a => a -> a -> a
`mappend` w'
w'
w'
wt w' -> n (b, s, w') -> n (b, s, w')
forall a b. a -> b -> b
`seq` (b, s, w') -> n (b, s, w')
forall a. a -> n a
forall (m :: * -> *) a. Monad m => a -> m a
return (b
a, s
s', w'
wt)
{-# INLINE mapRWST #-}
withRWST :: (r' -> s -> (r, s)) -> RWST r w s m a -> RWST r' w s m a
withRWST :: forall r' s r w (m :: * -> *) a.
(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 -> w -> m (a, s, w)) -> RWST r' w s m a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r' -> s -> w -> m (a, s, w)) -> RWST r' w s m a)
-> (r' -> s -> w -> m (a, s, w)) -> RWST r' w s m a
forall a b. (a -> b) -> a -> b
$ \ r'
r s
s -> (r -> s -> w -> m (a, s, w)) -> (r, s) -> w -> m (a, s, w)
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (RWST r w s m a -> r -> s -> w -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> w -> m (a, s, w)
unRWST 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 :: forall a b. (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 -> w -> m (b, s, w)) -> RWST r w s m b
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (b, s, w)) -> RWST r w s m b)
-> (r -> s -> w -> m (b, s, w)) -> RWST r w s m b
forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w -> (\ (a
a, s
s', w
w') -> (a -> b
f a
a, s
s', w
w')) ((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
<$> RWST r w s m a -> r -> s -> w -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> w -> m (a, s, w)
unRWST RWST r w s m a
m r
r s
s w
w
{-# INLINE fmap #-}
instance (Functor m, Monad m) => Applicative (RWST r w s m) where
pure :: forall a. a -> RWST r w s m a
pure a
a = (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
_ s
s w
w -> (a, s, w) -> m (a, s, w)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, s
s, w
w)
{-# INLINE pure #-}
RWST r -> s -> w -> m (a -> b, s, w)
mf <*> :: forall a b.
RWST r w s m (a -> b) -> RWST r w s m a -> RWST r w s m b
<*> RWST r -> s -> w -> m (a, s, w)
mx = (r -> s -> w -> m (b, s, w)) -> RWST r w s m b
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (b, s, w)) -> RWST r w s m b)
-> (r -> s -> w -> m (b, s, w)) -> RWST r w s m b
forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w -> do
(a -> b
f, s
s', w
w') <- r -> s -> w -> m (a -> b, s, w)
mf r
r s
s w
w
(a
x, s
s'', w
w'') <- r -> s -> w -> m (a, s, w)
mx r
r s
s' w
w'
(b, s, w) -> m (b, s, w)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b
f a
x, s
s'', w
w'')
{-# INLINE (<*>) #-}
instance (Functor m, MonadPlus m) => Alternative (RWST r w s m) where
empty :: forall a. RWST r w s m a
empty = (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
_ s
_ w
_ -> m (a, s, w)
forall a. m a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
{-# INLINE empty #-}
RWST r -> s -> w -> m (a, s, w)
m <|> :: forall a. RWST r w s m a -> RWST r w s m a -> RWST r w s m a
<|> RWST r -> s -> w -> m (a, s, w)
n = (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w -> r -> s -> w -> m (a, s, w)
m r
r s
s w
w m (a, s, w) -> m (a, s, w) -> m (a, s, w)
forall a. m a -> m a -> m a
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` r -> s -> w -> m (a, s, w)
n r
r s
s w
w
{-# INLINE (<|>) #-}
instance (Monad m) => Monad (RWST r w s m) where
#if !(MIN_VERSION_base(4,8,0))
return a = RWST $ \ _ s w -> return (a, s, w)
{-# INLINE return #-}
#endif
RWST r w s m a
m >>= :: forall a b.
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 -> w -> m (b, s, w)) -> RWST r w s m b
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (b, s, w)) -> RWST r w s m b)
-> (r -> s -> w -> m (b, s, w)) -> RWST r w s m b
forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w -> do
(a
a, s
s', w
w') <- RWST r w s m a -> r -> s -> w -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> w -> m (a, s, w)
unRWST RWST r w s m a
m r
r s
s w
w
RWST r w s m b -> r -> s -> w -> m (b, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> w -> m (a, s, w)
unRWST (a -> RWST r w s m b
k a
a) r
r s
s' 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 (Fail.MonadFail m) => Fail.MonadFail (RWST r w s m) where
fail :: forall a. String -> RWST r w s m a
fail String
msg = (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
_ s
_ w
_ -> String -> m (a, s, w)
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
Fail.fail String
msg
{-# INLINE fail #-}
#endif
instance (Functor m, MonadPlus m) => MonadPlus (RWST r w s m) where
mzero :: forall a. RWST r w s m a
mzero = RWST r w s m a
forall a. RWST r w s m a
forall (f :: * -> *) a. Alternative f => f a
empty
{-# INLINE mzero #-}
mplus :: forall a. RWST r w s m a -> RWST r w s m a -> RWST r w s m a
mplus = RWST r w s m a -> RWST r w s m a -> RWST r w s m a
forall a. RWST r w s m a -> RWST r w s m a -> RWST r w s m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
(<|>)
{-# INLINE mplus #-}
instance (MonadFix m) => MonadFix (RWST r w s m) where
mfix :: forall a. (a -> RWST r w s m a) -> RWST r w s m a
mfix a -> RWST r w s m a
f = (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w -> ((a, s, w) -> m (a, s, w)) -> m (a, s, w)
forall a. (a -> m a) -> m a
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 -> w -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> w -> m (a, s, w)
unRWST (a -> RWST r w s m a
f a
a) r
r s
s w
w
{-# INLINE mfix #-}
instance MonadTrans (RWST r w s) where
lift :: forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
lift m a
m = (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
_ s
s w
w -> do
a
a <- m a
m
(a, s, w) -> m (a, s, w)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, s
s, w
w)
{-# INLINE lift #-}
instance (MonadIO m) => MonadIO (RWST r w s m) where
liftIO :: forall a. IO a -> RWST r w s m a
liftIO = m a -> RWST r w s m a
forall (m :: * -> *) a. Monad m => 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 a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
{-# INLINE liftIO #-}
reader :: (Monad m) => (r -> a) -> RWST r w s m a
reader :: forall (m :: * -> *) r a w s. Monad m => (r -> a) -> RWST r w s m a
reader = (r -> a) -> RWST r w s m a
forall (m :: * -> *) r a w s. Monad m => (r -> a) -> RWST r w s m a
asks
{-# INLINE reader #-}
ask :: (Monad m) => RWST r w s m r
ask :: forall (m :: * -> *) r w s. Monad m => RWST r w s m r
ask = (r -> r) -> RWST r w s m r
forall (m :: * -> *) r a w s. Monad m => (r -> a) -> RWST r w s m a
asks r -> r
forall a. a -> a
id
{-# INLINE ask #-}
local :: (r -> r) -> RWST r w s m a -> RWST r w s m a
local :: forall r w s (m :: * -> *) a.
(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 -> w -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w -> RWST r w s m a -> r -> s -> w -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> w -> m (a, s, w)
unRWST RWST r w s m a
m (r -> r
f r
r) s
s w
w
{-# INLINE local #-}
asks :: (Monad m) => (r -> a) -> RWST r w s m a
asks :: forall (m :: * -> *) r a w s. Monad m => (r -> a) -> RWST r w s m a
asks r -> a
f = (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w -> (a, s, w) -> m (a, s, w)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (r -> a
f r
r, s
s, w
w)
{-# INLINE asks #-}
writer :: (Monoid w, Monad m) => (a, w) -> RWST r w s m a
writer :: forall w (m :: * -> *) a r s.
(Monoid w, Monad m) =>
(a, w) -> RWST r w s m a
writer (a
a, w
w') = (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
_ s
s w
w -> let wt :: w
wt = w
w w -> w -> w
forall a. Monoid a => a -> a -> a
`mappend` w
w' in w
wt w -> m (a, s, w) -> m (a, s, w)
forall a b. a -> b -> b
`seq` (a, s, w) -> m (a, s, w)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, s
s, w
wt)
{-# INLINE writer #-}
tell :: (Monoid w, Monad m) => w -> RWST r w s m ()
tell :: forall w (m :: * -> *) r s.
(Monoid w, Monad m) =>
w -> RWST r w s m ()
tell w
w' = ((), w) -> RWST r w s m ()
forall w (m :: * -> *) a r s.
(Monoid w, Monad m) =>
(a, w) -> RWST r w s m a
writer ((), w
w')
{-# INLINE tell #-}
listen :: (Monoid w, Monad m) => RWST r w s m a -> RWST r w s m (a, w)
listen :: forall w (m :: * -> *) r s a.
(Monoid w, Monad m) =>
RWST r w s m a -> RWST r w s m (a, w)
listen = (w -> w) -> RWST r w s m a -> RWST r w s m (a, w)
forall w (m :: * -> *) b r s a.
(Monoid w, Monad m) =>
(w -> b) -> RWST r w s m a -> RWST r w s m (a, b)
listens w -> w
forall a. a -> a
id
{-# INLINE listen #-}
listens :: (Monoid w, Monad m) => (w -> b) -> RWST r w s m a -> RWST r w s m (a, b)
listens :: forall w (m :: * -> *) b r s a.
(Monoid w, Monad m) =>
(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 -> w -> m ((a, b), s, w)) -> RWST r w s m (a, b)
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m ((a, b), s, w)) -> RWST r w s m (a, b))
-> (r -> s -> w -> m ((a, b), s, w)) -> RWST r w s m (a, b)
forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w -> do
(a
a, s
s', w
w') <- RWST r w s m a -> r -> s -> m (a, s, w)
forall w r s (m :: * -> *) a.
Monoid w =>
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m a
m r
r s
s
let wt :: w
wt = w
w w -> w -> w
forall a. Monoid a => a -> a -> a
`mappend` w
w'
w
wt w -> m ((a, b), s, w) -> m ((a, b), s, w)
forall a b. a -> b -> b
`seq` ((a, b), s, w) -> m ((a, b), s, w)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ((a
a, w -> b
f w
w'), s
s', w
wt)
{-# INLINE listens #-}
pass :: (Monoid w, Monoid w', Monad m) => RWST r w s m (a, w -> w') -> RWST r w' s m a
pass :: forall w w' (m :: * -> *) r s a.
(Monoid w, Monoid w', 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')
m = (r -> s -> w' -> m (a, s, w')) -> RWST r w' s m a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w' -> m (a, s, w')) -> RWST r w' s m a)
-> (r -> s -> w' -> m (a, s, w')) -> RWST r w' s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s w'
w -> 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 w r s (m :: * -> *) a.
Monoid w =>
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
let wt :: w'
wt = w'
w w' -> w' -> w'
forall a. Monoid a => a -> a -> a
`mappend` w -> w'
f w
w'
w'
wt w' -> m (a, s, w') -> m (a, s, w')
forall a b. a -> b -> b
`seq` (a, s, w') -> m (a, s, w')
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, s
s', w'
wt)
{-# INLINE pass #-}
censor :: (Monoid w, Monad m) => (w -> w) -> RWST r w s m a -> RWST r w s m a
censor :: forall w (m :: * -> *) r s a.
(Monoid w, Monad m) =>
(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 -> w -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w -> do
(a
a, s
s', w
w') <- RWST r w s m a -> r -> s -> m (a, s, w)
forall w r s (m :: * -> *) a.
Monoid w =>
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s m a
m r
r s
s
let wt :: w
wt = w
w w -> w -> w
forall a. Monoid a => a -> a -> a
`mappend` w -> w
f w
w'
w
wt w -> m (a, s, w) -> m (a, s, w)
forall a b. a -> b -> b
`seq` (a, s, w) -> m (a, s, w)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, s
s', w
wt)
{-# INLINE censor #-}
state :: (Monad m) => (s -> (a, s)) -> RWST r w s m a
state :: forall (m :: * -> *) s a r w.
Monad m =>
(s -> (a, s)) -> RWST r w s m a
state s -> (a, s)
f = (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
_ s
s w
w -> let (a
a, s
s') = s -> (a, s)
f s
s in (a, s, w) -> m (a, s, w)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, s
s', w
w)
{-# INLINE state #-}
get :: (Monad m) =>RWST r w s m s
get :: forall (m :: * -> *) r w s. Monad m => RWST r w s m s
get = (s -> s) -> RWST r w s m s
forall (m :: * -> *) s a r w. Monad m => (s -> a) -> RWST r w s m a
gets s -> s
forall a. a -> a
id
{-# INLINE get #-}
put :: (Monad m) =>s -> RWST r w s m ()
put :: forall (m :: * -> *) s r w. Monad m => s -> RWST r w s m ()
put s
s = (r -> s -> w -> m ((), s, w)) -> RWST r w s m ()
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m ((), s, w)) -> RWST r w s m ())
-> (r -> s -> w -> m ((), s, w)) -> RWST r w s m ()
forall a b. (a -> b) -> a -> b
$ \ r
_ s
_ w
w -> ((), s, w) -> m ((), s, w)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ((), s
s, w
w)
{-# INLINE put #-}
modify :: (Monad m) =>(s -> s) -> RWST r w s m ()
modify :: forall (m :: * -> *) s r w. Monad m => (s -> s) -> RWST r w s m ()
modify s -> s
f = (r -> s -> w -> m ((), s, w)) -> RWST r w s m ()
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m ((), s, w)) -> RWST r w s m ())
-> (r -> s -> w -> m ((), s, w)) -> RWST r w s m ()
forall a b. (a -> b) -> a -> b
$ \ r
_ s
s w
w -> ((), s, w) -> m ((), s, w)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ((), s -> s
f s
s, w
w)
{-# INLINE modify #-}
gets :: (Monad m) =>(s -> a) -> RWST r w s m a
gets :: forall (m :: * -> *) s a r w. Monad m => (s -> a) -> RWST r w s m a
gets s -> a
f = (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
_ s
s w
w -> (a, s, w) -> m (a, s, w)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (s -> a
f s
s, s
s, w
w)
{-# INLINE gets #-}
liftCallCC :: CallCC m (a,s,w) (b,s,w) -> CallCC (RWST r w s m) a b
liftCallCC :: forall (m :: * -> *) a s w b r.
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 -> w -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w ->
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 -> w -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> w -> m (a, s, w)
unRWST ((a -> RWST r w s m b) -> RWST r w s m a
f (\ a
a -> (r -> s -> w -> m (b, s, w)) -> RWST r w s m b
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (b, s, w)) -> RWST r w s m b)
-> (r -> s -> w -> m (b, s, w)) -> RWST r w s m b
forall a b. (a -> b) -> a -> b
$ \ r
_ s
_ w
_ -> (a, s, w) -> m (b, s, w)
c (a
a, s
s, w
w))) r
r s
s w
w
{-# INLINE liftCallCC #-}
liftCallCC' :: CallCC m (a,s,w) (b,s,w) -> CallCC (RWST r w s m) a b
liftCallCC' :: forall (m :: * -> *) a s w b r.
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 -> w -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w ->
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 -> w -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> w -> m (a, s, w)
unRWST ((a -> RWST r w s m b) -> RWST r w s m a
f (\ a
a -> (r -> s -> w -> m (b, s, w)) -> RWST r w s m b
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (b, s, w)) -> RWST r w s m b)
-> (r -> s -> w -> m (b, s, w)) -> RWST r w s m b
forall a b. (a -> b) -> a -> b
$ \ r
_ s
s' w
_ -> (a, s, w) -> m (b, s, w)
c (a
a, s
s', w
w))) r
r s
s w
w
{-# INLINE liftCallCC' #-}
liftCatch :: Catch e m (a,s,w) -> Catch e (RWST r w s m) a
liftCatch :: forall e (m :: * -> *) a s w r.
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 -> w -> m (a, s, w)) -> RWST r w s m a
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST ((r -> s -> w -> m (a, s, w)) -> RWST r w s m a)
-> (r -> s -> w -> m (a, s, w)) -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w -> RWST r w s m a -> r -> s -> w -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> w -> m (a, s, w)
unRWST RWST r w s m a
m r
r s
s w
w Catch e m (a, s, w)
`catchE` \ e
e -> RWST r w s m a -> r -> s -> w -> m (a, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> w -> m (a, s, w)
unRWST (e -> RWST r w s m a
h e
e) r
r s
s w
w
{-# INLINE liftCatch #-}