| Copyright | (c) Ivan Perez and Manuel Baerenz 2016 |
|---|---|
| License | BSD3 |
| Maintainer | ivan.perez@keera.co.uk |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Control.Monad.Trans.MSF.State
Contents
Description
MSFs with a State monadic layer.
This module contains functions to work with MSFs that include a State
monadic layer. This includes functions to create new MSFs that include an
additional layer, and functions to flatten that layer out of the MSF's
transformer stack.
It is based on the _strict_ state monad Strict,
so when combining it with other modules such as mtl's,
the strict version has to be included, i.e. Strict
instead of State or Lazy.
Synopsis
- newtype StateT s (m :: Type -> Type) a = StateT {
- runStateT :: s -> m (a, s)
- type State s = StateT s Identity
- liftCallCC' :: CallCC m (a, s) (b, s) -> CallCC (StateT s m) a b
- get :: forall (m :: Type -> Type) s. Monad m => StateT s m s
- put :: forall (m :: Type -> Type) s. Monad m => s -> StateT s m ()
- runState :: State s a -> s -> (a, s)
- evalState :: State s a -> s -> a
- execState :: State s a -> s -> s
- 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
- modifyM :: Monad m => (s -> m s) -> StateT s m ()
- stateS :: (Functor m, Monad m) => MSF m (s, a) (s, b) -> MSF (StateT s m) a b
- runStateS :: (Functor m, Monad m) => MSF (StateT s m) a b -> MSF m (s, a) (s, b)
- runStateS_ :: (Functor m, Monad m) => MSF (StateT s m) a b -> s -> MSF m a (s, b)
- runStateS__ :: (Functor m, Monad m) => MSF (StateT s m) a b -> s -> MSF m a b
Documentation
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
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.
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.
put :: forall (m :: Type -> Type) s. Monad m => s -> StateT s m () #
sets the state within the monad to put ss.
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 |
| -> a | return value of the state computation |
Arguments
| :: State s a | state-passing computation to execute |
| -> s | initial value |
| -> s | final state |
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.)
modifyM :: Monad m => (s -> m s) -> StateT s m () #
A variant of modify in which the new state is generated by a
monadic action.