HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulemonads-tf-0.3.0.1GHC2021

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
  • 2 values
classclass Monad m => MonadState (m :: Type -> Type) where
#

get returns the state from the internals of the monad.

put replaces the state inside the monad.

Associated types

Methods

Instances11MonadState, …
valuemodify :: MonadState m => (StateType m -> StateType m) -> 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.

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

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