{-# 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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST 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 forall a. Monoid a => a -> a -> a
`mappend` w
w' in w
wt seq :: forall a b. a -> b -> b
`seq` 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 = forall a. Identity a -> a
runIdentity (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) = 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) = 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 = 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 (forall a. a -> Identity a
Identity forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, s, w) -> (b, s, w')
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = 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 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
$cto :: forall r w s (m :: * -> *) a x.
Rep (RWST r w s m a) x -> RWST r w s m a
$cfrom :: forall r w s (m :: * -> *) a x.
RWST r w s m a -> Rep (RWST r w s m a) x
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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST 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 forall a. Monoid a => a -> a -> a
`mappend` w
w' in w
wt seq :: forall a b. a -> b -> b
`seq` (a
a, s
s', w
wt)) 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 = 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 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) <- 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
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) <- 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
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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST 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 (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 forall a. Monoid a => a -> a -> a
`mappend` w'
w'
w'
wt seq :: forall a b. a -> b -> b
`seq` 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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r'
r s
s -> forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST 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')) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
s w
w -> 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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST 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'
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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
_ w
_ -> 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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST 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 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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w -> do
(a
a, s
s', w
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
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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
_ w
_ -> 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 = 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 = 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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w -> forall (m :: * -> *) a. MonadFix m => (a -> m a) -> m a
mfix forall a b. (a -> b) -> a -> b
$ \ ~(a
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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
s w
w -> do
a
a <- m a
m
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 = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = 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 = forall (m :: * -> *) r a w s. Monad m => (r -> a) -> RWST r w s m a
asks 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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w -> 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') = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
s w
w -> let wt :: w
wt = w
w forall a. Monoid a => a -> a -> a
`mappend` w
w' in w
wt seq :: forall a b. a -> b -> b
`seq` 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' = 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 = 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 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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w -> do
(a
a, s
s', w
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 forall a. Monoid a => a -> a -> a
`mappend` w
w'
w
wt seq :: forall a b. a -> b -> b
`seq` 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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s w'
w -> do
((a
a, w -> w'
f), s
s', w
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 forall a. Monoid a => a -> a -> a
`mappend` w -> w'
f w
w'
w'
wt seq :: forall a b. a -> b -> b
`seq` 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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w -> do
(a
a, s
s', w
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 forall a. Monoid a => a -> a -> a
`mappend` w -> w
f w
w'
w
wt seq :: forall a b. a -> b -> b
`seq` 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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
s w
w -> let (a
a, s
s') = s -> (a, s)
f s
s in 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 = forall (m :: * -> *) s a r w. Monad m => (s -> a) -> RWST r w s m a
gets 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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
_ w
w -> 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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
s w
w -> 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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
s w
w -> 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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w ->
CallCC m (a, s, w) (b, s, w)
callCC forall a b. (a -> b) -> a -> b
$ \ (a, s, w) -> m (b, s, w)
c -> 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 -> forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST 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 = forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
w ->
CallCC m (a, s, w) (b, s, w)
callCC forall a b. (a -> b) -> a -> b
$ \ (a, s, w) -> m (b, s, w)
c -> 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 -> forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST 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 =
forall r w s (m :: * -> *) a.
(r -> s -> w -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s w
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 -> 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 #-}