Community
Modules 24

Control.Monad.State.Class

experimental

MonadState class.

This module is inspired by the paper Functional Programming with Overloading and Higher-Order Polymorphism, Mark P Jones (http://web.cecs.pdx.edu/~mpj/) Advanced School of Functional Programming, 1995.

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)
Build record and source files

Community contribution. The service has not verified this documentation. The generator reported 6 diagnostics.

Target: Linux on x86-64. Some inferred types and resolved links are not available.

Generator: aihc-haddock-858b1951-web-1

Metadata snapshot: 032b29dc8ecd03eaae7b1a84a40ef8560125381762749b2f47333bc9a4f4bb8e

Open the dependency plan · Download the documentation model

Import a package

Enter a package name and an exact version from Hackage. The site contains imported versions only.