class Monad m => MonadState s m
Minimal definition is either both of get and put or just state
get :: m s
Return the state from the internals of the monad.
put :: s -> m ()
Replace the state inside the monad.
state :: (s -> (a, s)) -> m a
Embed a simple state action into the monad.
modify :: MonadState s m => (s -> s) -> m ()
Monadic state transformer.
Maps an old state to a new state inside a state monad.
The old state is thrown away.
Main> :t modify ((+1) :: Int -> Int)
modify (...) :: (MonadState Int a) => a ()
This says that modify (+1) acts over any
Monad that is a member of the MonadState class,
with an Int state.
modify' :: MonadState s m => (s -> s) -> m ()
A variant of modify in which the computation is strict in the
new state.
gets :: MonadState s m => (s -> a) -> m a
Gets specific component of the state, using a projection function
supplied.
Instances
16
instance Monad m => MonadState s (Lazy.StateT s m)instance Monad m => MonadState s (Strict.StateT s m)instance (Monad m, Monoid w) => MonadState s (CPSRWS.RWST r w s m)instance (Monad m, Monoid w) => MonadState s (LazyRWS.RWST r w s m)instance (Monad m, Monoid w) => MonadState s (StrictRWS.RWST r w s m)instance MonadState s m => MonadState s (ContT r m)instance MonadState s m => MonadState s (ExceptT e m)instance MonadState s m => MonadState s (IdentityT m)instance MonadState s m => MonadState s (MaybeT m)instance MonadState s m => MonadState s (ReaderT r m)instance (Monoid w, MonadState s m) => MonadState s (CPS.WriterT w m)instance (Monoid w, MonadState s m) => MonadState s (Lazy.WriterT w m)instance (Monoid w, MonadState s m) => MonadState s (Strict.WriterT w m)instance (Monoid w, MonadState s m) => MonadState s (AccumT w m)instance MonadState s m => MonadState s (SelectT r m)instance (MonadState s m, MonadState s n) => MonadState s (Product m n)
- Maintainer
- libraries@haskell.org
- Portability
- non-portable (multi-param classes, functional dependencies)
- Copyright
- (c) Andy Gill 2001, (c) Oregon Graduate Institute of Science and Technology, 2001
- License
- BSD-style (see the file LICENSE)