| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Control.Monad.Ology.Specific.StateT
Contents
Synopsis
- get :: forall (m :: Type -> Type) s. Monad m => StateT s m s
- newtype StateT s (m :: Type -> Type) a = StateT {
- runStateT :: s -> m (a, s)
- put :: forall (m :: Type -> Type) s. Monad m => s -> StateT s m ()
- type State s = StateT s Identity
- runState :: State s a -> s -> (a, s)
- execState :: State s a -> s -> s
- evalState :: State s a -> s -> a
- mapState :: ((a, s) -> (b, s)) -> State s a -> State s b
- withState :: (s -> s) -> State s a -> State s a
- evalStateT :: Monad m => StateT s m a -> s -> m a
- execStateT :: Monad m => StateT s m a -> s -> m s
- mapStateT :: (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b
- withStateT :: forall s (m :: Type -> Type) a. (s -> s) -> StateT s m a -> StateT s m a
- state :: forall (m :: Type -> Type) s a. Monad m => (s -> (a, s)) -> StateT s m a
- 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 ()
- gets :: forall (m :: Type -> Type) s a. Monad m => (s -> a) -> StateT s m a
- liftCallCC' :: CallCC m (a, s) (b, s) -> CallCC (StateT s m) a b
- modifyM :: Monad m => (s -> m s) -> StateT s m ()
- liftWithMVarStateT :: MonadIO m => (MVar s -> m a) -> StateT s m a
- mVarRunStateT :: MVar s -> Unlift MonadTunnelIO (StateT s)
- mVarRunLocked :: forall (m :: Type -> Type) s. MonadTunnelIO m => MVar s -> m --> m
- discardingStateTUnlift :: s -> Unlift MonadIO (StateT s)
- dangerousMVarRunStateT :: MVar s -> Unlift MonadIO (StateT s)
- liftStateT :: forall f (m :: Type -> Type) s a. (Traversable f, Applicative m) => StateT s m a -> StateT (f s) m (f a)
Documentation
get :: forall (m :: Type -> Type) s. Monad m => StateT s m s #
Fetch the current value of the state within the monad.
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
put :: forall (m :: Type -> Type) s. Monad m => s -> StateT s m () #
sets the state within the monad to put ss.
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.
Arguments
| :: 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.)
Arguments
| :: State s a | state-passing computation to execute |
| -> s | initial value |
| -> s | final state |
Arguments
| :: 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.
evalStateTm s =liftMfst(runStateTm s)
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.
execStateTm s =liftMsnd(runStateTm s)
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.
withStateTf m =modifyf >> m
Arguments
| :: 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.)
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).
modifyM :: Monad m => (s -> m s) -> StateT s m () #
A variant of modify in which the new state is generated by a
monadic action.
mVarRunStateT :: MVar s -> Unlift MonadTunnelIO (StateT s) Source #
mVarRunLocked :: forall (m :: Type -> Type) s. MonadTunnelIO 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 :: forall f (m :: Type -> Type) s a. (Traversable f, Applicative m) => StateT s m a -> StateT (f s) m (f a) Source #
Orphan instances
| TransConstraint MonadFail (StateT s) Source # | |
| TransConstraint MonadFix (StateT s) Source # | |
| TransConstraint MonadIO (StateT s) Source # | |
| TransConstraint Functor (StateT s) Source # | |
| TransConstraint Monad (StateT s) Source # | |
| TransConstraint MonadPlus (StateT s) Source # | |
| TransConstraint MonadException (StateT s) Source # | |
Methods hasTransConstraint :: forall (m :: Type -> Type). MonadException m => Dict (MonadException (StateT s m)) Source # | |
| MonadCatch e m => MonadCatch e (StateT s m) Source # | |
| MonadThrow e m => MonadThrow e (StateT s m) Source # | |
| MonadTransCoerce (StateT a) Source # | |
| MonadTransHoist (StateT s) Source # | |
| MonadTransTunnel (StateT s) Source # | |
| MonadTransUnlift (StateT s) Source # | |
Methods liftWithUnlift :: MonadIO m => (Unlift MonadTunnelIO (StateT s) -> m r) -> StateT s m r Source # getDiscardingUnlift :: forall (m :: Type -> Type). Monad m => StateT s m (WUnlift MonadTunnelIO (StateT s)) Source # | |
| TransConstraint (MonadCatch e) (StateT s) Source # | |
Methods hasTransConstraint :: forall (m :: Type -> Type). MonadCatch e m => Dict (MonadCatch e (StateT s m)) Source # | |
| TransConstraint (MonadThrow e) (StateT s) Source # | |
Methods hasTransConstraint :: forall (m :: Type -> Type). MonadThrow e m => Dict (MonadThrow e (StateT s m)) Source # | |
| MonadException m => MonadException (StateT s m) Source # | |