{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE Safe #-}
#endif
#if __GLASGOW_HASKELL__ >= 710
{-# LANGUAGE AutoDeriveTypeable #-}
#endif
module Control.Monad.Trans.RWS.Strict (
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 :: forall r s a 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 -> m (a, s, w)) -> RWST r w s m a
RWST (\ r
r s
s -> 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 :: 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 = forall a. Identity a -> a
runIdentity (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 :: forall r w s a. 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 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 :: forall r w s a. 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 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 :: forall a s w b w' r.
((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 (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 (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 -> 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 :: forall (m :: * -> *) r w s a.
Monad m =>
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 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
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 :: forall (m :: * -> *) r w s a.
Monad m =>
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 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
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 :: 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 m (a, s, w) -> n (b, s, w')
f RWST r w s m a
m = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> m (a, s, w) -> n (b, s, w')
f (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 :: 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 -> 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 -> 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 :: 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 -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s ->
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)) forall a b. (a -> b) -> a -> b
$ 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 :: forall a. a -> RWST r w s m a
pure a
a = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, s
s, forall a. Monoid a => a
mempty)
{-# INLINE pure #-}
RWST r -> s -> 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 -> m (a, s, w)
mx = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST 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'
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b
f a
x, s
s'', 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 :: forall a. RWST r w s m a
empty = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
_ -> forall (m :: * -> *) a. MonadPlus m => m a
mzero
{-# INLINE empty #-}
RWST r -> s -> 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 -> m (a, s, w)
n = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> r -> s -> m (a, s, w)
m r
r s
s 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 >>= :: 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 -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> do
(a
a, s
s', w
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') <- 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'
forall (m :: * -> *) a. Monad m => a -> m a
return (b
b, s
s'', 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 :: forall a. String -> RWST r w s m a
fail String
msg = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
_ -> 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 :: forall a. RWST r w s m a
mzero = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
_ -> forall (m :: * -> *) a. MonadPlus m => m a
mzero
{-# INLINE mzero #-}
RWST r -> s -> m (a, s, w)
m mplus :: forall a. 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 = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> r -> s -> m (a, s, w)
m r
r s
s 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 :: 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 -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> 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 -> 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 :: 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 -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
s -> do
a
a <- m a
m
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, s
s, forall a. Monoid a => a
mempty)
{-# INLINE lift #-}
instance (Monoid w, 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 #-}
#if MIN_VERSION_base(4,12,0)
instance Contravariant m => Contravariant (RWST r w s m) where
contramap :: forall a' a. (a' -> a) -> RWST r w s m a -> RWST r w s m a'
contramap a' -> a
f RWST r w s m a
m = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \r
r s
s ->
forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap (\ (a'
a, s
s', w
w) -> (a' -> a
f a'
a, s
s', w
w)) forall a b. (a -> b) -> a -> b
$ 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 contramap #-}
#endif
reader :: (Monoid w, Monad m) => (r -> a) -> RWST r w s m a
reader :: forall w (m :: * -> *) r a s.
(Monoid w, Monad m) =>
(r -> a) -> RWST r w s m a
reader = 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 :: forall w (m :: * -> *) r s. (Monoid w, Monad m) => RWST r w s m r
ask = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return (r
r, s
s, forall a. Monoid a => a
mempty)
{-# 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 -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> 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 :: forall w (m :: * -> *) r a s.
(Monoid w, Monad m) =>
(r -> a) -> RWST r w s m a
asks r -> a
f = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return (r -> a
f r
r, s
s, forall a. Monoid a => a
mempty)
{-# INLINE asks #-}
writer :: (Monad m) => (a, w) -> RWST r w s m a
writer :: forall (m :: * -> *) a w r s. Monad m => (a, w) -> RWST r w s m a
writer (a
a, w
w) = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
s -> 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 :: forall (m :: * -> *) w r s. Monad m => w -> RWST r w s m ()
tell w
w = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
s -> 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 :: forall (m :: * -> *) r w s a.
Monad m =>
RWST r w s m a -> RWST r w s m (a, w)
listen RWST r w s m a
m = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> do
(a
a, s
s', w
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
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 :: forall (m :: * -> *) w b r s a.
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 -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> do
(a
a, s
s', w
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
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 :: forall (m :: * -> *) r w s a.
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 -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> do
((a
a, w -> w
f), s
s', w
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
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 :: forall (m :: * -> *) w r s a.
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 -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> do
(a
a, s
s', w
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
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 :: forall w (m :: * -> *) s a r.
(Monoid 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 -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
s -> case s -> (a, s)
f s
s of (a
a,s
s') -> forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, s
s', forall a. Monoid a => a
mempty)
{-# INLINE state #-}
get :: (Monoid w, Monad m) => RWST r w s m s
get :: forall w (m :: * -> *) r s. (Monoid w, Monad m) => RWST r w s m s
get = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return (s
s, s
s, forall a. Monoid a => a
mempty)
{-# INLINE get #-}
put :: (Monoid w, Monad m) => s -> RWST r w s m ()
put :: forall w (m :: * -> *) s r.
(Monoid w, Monad m) =>
s -> RWST r w s m ()
put s
s = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return ((), s
s, forall a. Monoid a => a
mempty)
{-# INLINE put #-}
modify :: (Monoid w, Monad m) => (s -> s) -> RWST r w s m ()
modify :: forall w (m :: * -> *) s r.
(Monoid w, Monad m) =>
(s -> s) -> RWST r w s m ()
modify s -> s
f = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return ((), s -> s
f s
s, forall a. Monoid a => a
mempty)
{-# INLINE modify #-}
gets :: (Monoid w, Monad m) => (s -> a) -> RWST r w s m a
gets :: forall w (m :: * -> *) s a r.
(Monoid w, Monad m) =>
(s -> a) -> RWST r w s m a
gets s -> a
f = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return (s -> a
f s
s, s
s, 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 :: forall w (m :: * -> *) a s b r.
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 (a -> RWST r w s m b) -> RWST r w s m a
f = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s ->
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 -> m (a, s, w)
runRWST ((a -> RWST r w s m b) -> RWST r w s m a
f (\ a
a -> forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
_ -> (a, s, w) -> m (b, s, w)
c (a
a, s
s, 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' :: forall w (m :: * -> *) a s b r.
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 (a -> RWST r w s m b) -> RWST r w s m a
f = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s ->
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 -> m (a, s, w)
runRWST ((a -> RWST r w s m b) -> RWST r w s m a
f (\ a
a -> forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
_ s
s' -> (a, s, w) -> m (b, s, w)
c (a
a, s
s', 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 :: 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 -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> 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 -> 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 #-}