Copyright | (c) Edward Kmett & Sjoerd Visscher 2011 |
---|---|
License | BSD3 |
Maintainer | ekmett@gmail.com |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell98 |
A generalized State monad, parameterized by a Representable functor. The representation of that functor serves as the state.
Synopsis
- type State g = StateT g Identity
- runState :: Representable g => State g a -> Rep g -> (a, Rep g)
- evalState :: Representable g => State g a -> Rep g -> a
- execState :: Representable g => State g a -> Rep g -> Rep g
- mapState :: Functor g => ((a, Rep g) -> (b, Rep g)) -> State g a -> State g b
- newtype StateT g m a = StateT {}
- stateT :: Representable g => (Rep g -> m (a, Rep g)) -> StateT g m a
- runStateT :: Representable g => StateT g m a -> Rep g -> m (a, Rep g)
- evalStateT :: (Representable g, Monad m) => StateT g m a -> Rep g -> m a
- execStateT :: (Representable g, Monad m) => StateT g m a -> Rep g -> m (Rep g)
- mapStateT :: Functor g => (m (a, Rep g) -> n (b, Rep g)) -> StateT g m a -> StateT g n b
- liftCallCC :: Representable g => ((((a, Rep g) -> m (b, Rep g)) -> m (a, Rep g)) -> m (a, Rep g)) -> ((a -> StateT g m b) -> StateT g m a) -> StateT g m a
- liftCallCC' :: Representable g => ((((a, Rep g) -> m (b, Rep g)) -> m (a, Rep g)) -> m (a, Rep g)) -> ((a -> StateT g m b) -> StateT g m a) -> StateT g m a
- class Monad m => MonadState s (m :: Type -> Type) | m -> s where
Documentation
type State g = StateT g Identity #
A memoized state monad parameterized by a representable functor g
, where
the representatation of g
, Rep g
is 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.
:: Representable g | |
=> State g a | state-passing computation to execute |
-> Rep g | initial state |
-> (a, Rep g) | return value and final state |
Unwrap a state monad computation as a function.
(The inverse of state
.)
:: Representable g | |
=> State g a | state-passing computation to execute |
-> Rep g | initial value |
-> a | return value of the state computation |
:: Representable g | |
=> State g a | state-passing computation to execute |
-> Rep g | initial value |
-> Rep g | final state |
A state transformer monad parameterized by:
g
- A representable functor used to memoize results for a stateRep g
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
(Functor f, Representable g, MonadFree f m) => MonadFree f (StateT g m) # | |
Defined in Control.Monad.Representable.State | |
(Representable g, MonadWriter w m) => MonadWriter w (StateT g m) # | |
(Representable g, Monad m, Rep g ~ s) => MonadState s (StateT g m) # | |
(Representable g, MonadReader e m) => MonadReader e (StateT g m) # | |
Representable f => MonadTrans (StateT f) # | |
Defined in Control.Monad.Representable.State | |
Representable f => BindTrans (StateT f) # | |
Defined in Control.Monad.Representable.State | |
(Representable g, Monad m) => Monad (StateT g m) # | |
(Functor g, Functor m) => Functor (StateT g m) # | |
(Representable g, Functor m, Monad m) => Applicative (StateT g m) # | |
Defined in Control.Monad.Representable.State | |
(Representable g, MonadCont m) => MonadCont (StateT g m) # | |
(Representable g, Bind m) => Apply (StateT g m) # | |
(Representable g, Bind m) => Bind (StateT g m) # | |
evalStateT :: (Representable g, Monad m) => StateT g m a -> Rep g -> 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)
execStateT :: (Representable g, Monad m) => StateT g m a -> Rep g -> m (Rep g) #
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)
liftCallCC :: Representable g => ((((a, Rep g) -> m (b, Rep g)) -> m (a, Rep g)) -> m (a, Rep g)) -> ((a -> StateT g m b) -> StateT g m a) -> StateT g m a #
Uniform lifting of a callCC
operation to the new monad.
This version rolls back to the original state on entering the
continuation.
liftCallCC' :: Representable g => ((((a, Rep g) -> m (b, Rep g)) -> m (a, Rep g)) -> m (a, Rep g)) -> ((a -> StateT g m b) -> StateT g m a) -> StateT g m a #
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 laws of a monad transformer.
class Monad m => MonadState s (m :: Type -> Type) | m -> s where #
Minimal definition is either both of get
and put
or just state
Return the state from the internals of the monad.
Replace the state inside the monad.
state :: (s -> (a, s)) -> m a #
Embed a simple state action into the monad.
Instances
MonadState s m => MonadState s (MaybeT m) | |
MonadState s m => MonadState s (ListT m) | |
(Functor m, MonadState s m) => MonadState s (Free m) | |
(Representable g, Monad m, Rep g ~ s) => MonadState s (StateT g m) # | |
(Monoid w, MonadState s m) => MonadState s (WriterT w m) | |
(Monoid w, MonadState s m) => MonadState s (WriterT w m) | |
Monad m => MonadState s (StateT s m) | |
Monad m => MonadState s (StateT s m) | |
MonadState s m => MonadState s (ReaderT r m) | |
MonadState s m => MonadState s (IdentityT m) | |
MonadState s m => MonadState s (ExceptT e m) | Since: mtl-2.2 |
(Error e, MonadState s m) => MonadState s (ErrorT e m) | |
(Functor f, MonadState s m) => MonadState s (FreeT f m) | |
MonadState s m => MonadState s (ContT r m) | |
(Monad m, Monoid w) => MonadState s (RWST r w s m) | |
(Monad m, Monoid w) => MonadState s (RWST r w s m) | |