HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulemtl-2.3.1Haskell2010

Control.Monad.State.Class

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.

  • 1 class
  • 3 values
  • Packagemtl-2.3.1
  • Exports4
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceClass.hs
classclass Monad m => MonadState s (m :: Type -> Type) | m -> s where
#

Minimal definition is either both of get and put or just state

Methods

  • 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.

Instances15MonadState, …
valuemodify :: 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.

valuemodify' :: MonadState s m => (s -> s) -> m ()
#

A variant of modify in which the computation is strict in the new state.

valuegets :: MonadState s m => (s -> a) -> m a
#

Gets specific component of the state, using a projection function supplied.