Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- evalState :: State s a -> s -> a
- evalStateT :: Monad m => StateT s m a -> s -> m a
- execState :: State s a -> s -> s
- execStateT :: Monad m => StateT s m a -> s -> m s
- mapState :: ((a, s) -> (b, s)) -> State s a -> State s b
- mapStateT :: (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b
- runState :: State s a -> s -> (a, s)
- withState :: (s -> s) -> State s a -> State s a
- withStateT :: forall s (m :: Type -> Type) a. (s -> s) -> StateT s m a -> StateT s m a
- type State s = StateT s Identity
- newtype StateT s (m :: Type -> Type) a = StateT {
- runStateT :: s -> m (a, s)
- state :: forall (m :: Type -> Type) s a. Monad m => (s -> (a, s)) -> StateT s m a
- put :: forall (m :: Type -> Type) s. Monad m => s -> StateT s m ()
- modify' :: forall (m :: Type -> Type) s. Monad m => (s -> s) -> StateT s m ()
- modify :: forall (m :: Type -> Type) s. Monad m => (s -> s) -> StateT s m ()
- liftCallCC' :: CallCC m (a, s) (b, s) -> CallCC (StateT s m) a b
- gets :: forall (m :: Type -> Type) s a. Monad m => (s -> a) -> StateT s m a
- get :: forall (m :: Type -> Type) s. Monad m => StateT s m s
- mVarRunStateT :: MVar s -> Unlift MonadTunnelIOInner (StateT s)
- mVarRunLocked :: MonadTunnelIOInner m => MVar s -> m --> m
- discardingStateTUnlift :: s -> Unlift MonadIO (StateT s)
- dangerousMVarRunStateT :: MVar s -> Unlift MonadIO (StateT s)
- liftStateT :: (Traversable f, Applicative m) => StateT s m a -> StateT (f s) m (f a)
- liftWithMVarStateT :: MonadIO m => (MVar s -> m a) -> StateT s m a
Documentation
:: State s a | state-passing computation to execute |
-> s | initial value |
-> a | return value of the state computation |
evalStateT :: Monad m => StateT s m a -> s -> m a #
Evaluate a state computation with the given initial state and return the final value, discarding the final state.
evalStateT
m s =liftM
fst
(runStateT
m s)
:: State s a | state-passing computation to execute |
-> s | initial value |
-> s | final state |
execStateT :: Monad m => StateT s m a -> s -> m s #
Evaluate a state computation with the given initial state and return the final state, discarding the final value.
execStateT
m s =liftM
snd
(runStateT
m s)
:: State s a | state-passing computation to execute |
-> s | initial state |
-> (a, s) | return value and final state |
Unwrap a state monad computation as a function.
(The inverse of state
.)
withStateT :: forall s (m :: Type -> Type) a. (s -> s) -> StateT s m a -> StateT s m a #
executes action withStateT
f mm
on a state modified by
applying f
.
withStateT
f m =modify
f >> m
type State s = StateT s Identity #
A state monad parameterized by the type s
of the state to carry.
The return
function leaves the state unchanged, while >>=
uses
the final state of the first computation as the initial state of
the second.
newtype StateT s (m :: Type -> Type) a #
A state transformer monad parameterized by:
s
- The state.m
- The inner monad.
The return
function leaves the state unchanged, while >>=
uses
the final state of the first computation as the initial state of
the second.
Instances
:: forall (m :: Type -> Type) s a. Monad m | |
=> (s -> (a, s)) | pure state transformer |
-> StateT s m a | equivalent state-passing computation |
Construct a state monad computation from a function.
(The inverse of runState
.)
put :: forall (m :: Type -> Type) s. Monad m => s -> StateT s m () #
sets the state within the monad to put
ss
.
liftCallCC' :: CallCC m (a, s) (b, s) -> CallCC (StateT s m) a b #
In-situ lifting of a callCC
operation to the new monad.
This version uses the current state on entering the continuation.
It does not satisfy the uniformity property (see Control.Monad.Signatures).
get :: forall (m :: Type -> Type) s. Monad m => StateT s m s #
Fetch the current value of the state within the monad.
mVarRunStateT :: MVar s -> Unlift MonadTunnelIOInner (StateT s) Source #
mVarRunLocked :: MonadTunnelIOInner m => MVar s -> m --> m Source #
Take the MVar
before and put it back after.
dangerousMVarRunStateT :: MVar s -> Unlift MonadIO (StateT s) Source #
Dangerous, because the MVar won't be released on exception.
liftStateT :: (Traversable f, Applicative m) => StateT s m a -> StateT (f s) m (f a) Source #