Copyright | (c) Ivan Perez and Manuel Baerenz 2016 |
---|---|
License | BSD3 |
Maintainer | ivan.perez@keera.co.uk |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
MSF
s with a State
monadic layer.
This module contains functions to work with MSF
s that include a State
monadic layer. This includes functions to create new MSF
s 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
- 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
- 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
:: 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
MonadSplit g m => MonadSplit g (StateT s m) | |
Defined in Control.Monad.Random.Class | |
MonadBase b m => MonadBase b (StateT s m) | |
Defined in Control.Monad.Base | |
MonadTrans (StateT s) | |
Defined in Control.Monad.Trans.State.Strict | |
MonadInterleave m => MonadInterleave (StateT s m) | |
Defined in Control.Monad.Random.Class interleave :: StateT s m a -> StateT s m a # | |
MonadRandom m => MonadRandom (StateT s m) | |
Defined in Control.Monad.Random.Class | |
MonadFail m => MonadFail (StateT s m) | |
Defined in Control.Monad.Trans.State.Strict | |
MonadFix m => MonadFix (StateT s m) | |
Defined in Control.Monad.Trans.State.Strict | |
MonadIO m => MonadIO (StateT s m) | |
Defined in Control.Monad.Trans.State.Strict | |
Contravariant m => Contravariant (StateT s m) | |
(Functor m, MonadPlus m) => Alternative (StateT s m) | |
(Functor m, Monad m) => Applicative (StateT s m) | |
Defined in Control.Monad.Trans.State.Strict | |
Functor m => Functor (StateT s m) | |
Monad m => Monad (StateT s m) | |
MonadPlus m => MonadPlus (StateT s m) | |
:: 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.