State +Control.Monad.Trans +transformers
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.
Construct a state monad computation from a state transformer function.
Construct a state monad computation from a function. (The inverse of runState.)
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.
Evaluate a state computation with the given initial state and return the final value, discarding the final state.
* m s = fst (runState m
>
Evaluate a state computation with the given initial state and return the final value, discarding the final state.
* m s = liftM fst
> (runStateT m
Evaluate a state computation with the given initial state and return the final state, discarding the final value.
* m s = snd (runState m
>
Evaluate a state computation with the given initial state and return the final state, discarding the final value.
* m s = liftM snd
> (runStateT m
Map both the return value and final state of a computation using the given function.
* (mapState f m) = f . runState
Map both the return value and final state of a computation using the given function.
* (mapStateT f m) = f .
> runStateT
Unwrap a state monad computation as a function. (The inverse of state.)
withState f m executes action m on a state modified by applying f.
* f m = modify f >>
withStateT f m executes action m on a state modified by applying f.
* f m = modify f >>