| Safe Haskell | Safe |
|---|---|
| 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.
Synopsis
- newtype StateT s (m :: * -> *) a = StateT {
- runStateT :: s -> m (a, s)
- type State s = StateT s Identity
- 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 :: (s -> s) -> StateT s m a -> StateT s m a
- liftCallCC' :: CallCC m (a, s) (b, s) -> CallCC (StateT s m) a b
- gets :: Monad m => (s -> a) -> StateT s m a
- modify' :: Monad m => (s -> s) -> StateT s m ()
- modify :: Monad m => (s -> s) -> StateT s m ()
- put :: Monad m => s -> StateT s m ()
- get :: Monad m => StateT s m s
- state :: Monad m => (s -> (a, s)) -> StateT s m a
- stateS :: Monad m => MSF m (s, a) (s, b) -> MSF (StateT s m) a b
- runStateS :: Monad m => MSF (StateT s m) a b -> MSF m (s, a) (s, b)
- runStateS_ :: Monad m => MSF (StateT s m) a b -> s -> MSF m a (s, b)
- runStateS__ :: Monad m => MSF (StateT s m) a b -> s -> MSF m a b
- 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 -> MSF m (s, a) (s, b)
- runStateS''' :: (Functor m, Monad m) => MSF (StateT s m) a b -> MSF m (s, a) (s, b)
Documentation
newtype StateT s (m :: * -> *) 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.
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 :: (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
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).
Arguments
| :: 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.)
State MSF runningwrappingunwrapping
runStateS_ :: Monad m => MSF (StateT s m) a b -> s -> MSF m a (s, b) #
Build an MSF function that takes a fixed state as additional input, from
an MSF in the State monad, and outputs the new state with every
transformation step.
This should be always equal to:
runStateS_ msf s = feedback s $ runStateS msf >>> arr ((s,b) -> ((s,b), s))
although possibly more efficient.
runStateS__ :: Monad m => MSF (StateT s m) a b -> s -> MSF m a b #
Build an MSF function that takes a fixed state as additional
input, from an MSF in the State monad.
This should be always equal to:
runStateS__ msf s = feedback s $ runStateS msf >>> arr ((s,b) -> (b, s))
although possibly more efficient.