Control.Monad.State.Trans
- Package
- purescript-transformers
- Repository
- purescript/purescript-transformers
This module defines the state monad transformer, StateT.
#StateT Source
newtype StateT :: Type -> (Type -> Type) -> Type -> Typenewtype StateT s m a
The state monad transformer.
This monad transformer extends the base monad with the operations get
and put which can be used to model a single piece of mutable state.
The MonadState type class describes the operations supported by this monad.
Constructors
Instances
Newtype (StateT s m a) _(Functor m) => Functor (StateT s m)(Monad m) => Apply (StateT s m)(Monad m) => Applicative (StateT s m)(Monad m, Alt m) => Alt (StateT s m)(Monad m, Plus m) => Plus (StateT s m)(Monad m, Alternative m) => Alternative (StateT s m)(Monad m) => Bind (StateT s m)(Monad m) => Monad (StateT s m)(MonadRec m) => MonadRec (StateT s m)(MonadPlus m) => MonadPlus (StateT s m)MonadTrans (StateT s)Lazy (StateT s m a)(MonadEffect m) => MonadEffect (StateT s m)(MonadCont m) => MonadCont (StateT s m)(MonadThrow e m) => MonadThrow e (StateT s m)(MonadError e m) => MonadError e (StateT s m)(MonadAsk r m) => MonadAsk r (StateT s m)(MonadReader r m) => MonadReader r (StateT s m)(Monad m) => MonadState s (StateT s m)(MonadTell w m) => MonadTell w (StateT s m)(MonadWriter w m) => MonadWriter w (StateT s m)(Monad m, Semigroup a) => Semigroup (StateT s m a)(Monad m, Monoid a) => Monoid (StateT s m a)(MonadST s m) => MonadST s (StateT s' m)
#evalStateT Source
evalStateT :: forall s m a. Functor m => StateT s m a -> s -> m aRun a computation in the StateT monad, discarding the final state.
#execStateT Source
execStateT :: forall s m a. Functor m => StateT s m a -> s -> m sRun a computation in the StateT monad discarding the result.
#withStateT Source
withStateT :: forall s m a. (s -> s) -> StateT s m a -> StateT s m aModify the final state in a StateT monad action.
Re-exports from Control.Monad.State.Class
#MonadState Source
class MonadState :: Type -> (Type -> Type) -> Constraintclass (Monad m) <= MonadState s m | m -> s where
The MonadState s type class represents those monads which support a single piece of mutable
state of type s.
state fupdates the state using the functionf.
An implementation is provided for StateT, and for other monad transformers
defined in this library.
Laws:
do { get ; get } = getdo { put x ; put y } = put ydo { put x ; get } = put x $> xdo { s <- get ; put s } = pure unit
Members
#put Source
put :: forall m s. MonadState s m => s -> m UnitSet the state.
#modify_ Source
modify_ :: forall s m. MonadState s m => (s -> s) -> m Unit#modify Source
modify :: forall s m. MonadState s m => (s -> s) -> m sModify the state by applying a function to the current state. The returned value is the new state value.
#gets Source
gets :: forall s m a. MonadState s m => (s -> a) -> m aGet a value which depends on the current state.
#get Source
get :: forall m s. MonadState s m => m sGet the current state.
Re-exports from Control.Monad.Trans.Class
#MonadTrans Source
class MonadTrans :: ((Type -> Type) -> Type -> Type) -> Constraintclass MonadTrans t where
The MonadTrans type class represents monad transformers.
A monad transformer is a type constructor of kind (* -> *) -> * -> *, which
takes a Monad as its first argument, and returns another Monad.
This allows us to add additional effects to an existing monad. By iterating this process, we create monad transformer stacks, which contain all of the effects required for a particular computation.
The laws state that lift is a Monad morphism.
Laws:
lift (pure a) = pure alift (do { x <- m ; y }) = do { x <- lift m ; lift y }
Members
- Modules
- Control.
Comonad. Env - Control.
Comonad. Env. Class - Control.
Comonad. Env. Trans - Control.
Comonad. Store - Control.
Comonad. Store. Class - Control.
Comonad. Store. Trans - Control.
Comonad. Traced - Control.
Comonad. Traced. Class - Control.
Comonad. Traced. Trans - Control.
Comonad. Trans. Class - Control.
Monad. Cont - Control.
Monad. Cont. Class - Control.
Monad. Cont. Trans - Control.
Monad. Error. Class - Control.
Monad. Except - Control.
Monad. Except. Trans - Control.
Monad. Identity. Trans - Control.
Monad. List. Trans - Control.
Monad. Maybe. Trans - Control.
Monad. RWS - Control.
Monad. RWS. Trans - Control.
Monad. Reader - Control.
Monad. Reader. Class - Control.
Monad. Reader. Trans - Control.
Monad. State - Control.
Monad. State. Class - Control.
Monad. State. Trans - Control.
Monad. Trans. Class - Control.
Monad. Writer - Control.
Monad. Writer. Class - Control.
Monad. Writer. Trans