1 -----------------------------------------------------------------------------
3 -- Module : Control.Monad.State.Class
4 -- Copyright : (c) Andy Gill 2001,
5 -- (c) Oregon Graduate Institute of Science and Technology, 2001
6 -- License : BSD-style (see the file libraries/base/LICENSE)
8 -- Maintainer : libraries@haskell.org
9 -- Stability : experimental
10 -- Portability : non-portable (multi-param classes, functional dependencies)
14 -- This module is inspired by the paper
15 -- /Functional Programming with Overloading and
16 -- Higher-Order Polymorphism/,
17 -- Mark P Jones (<http://web.cecs.pdx.edu/~mpj/>)
18 -- Advanced School of Functional Programming, 1995.
20 -----------------------------------------------------------------------------
21 {-# LANGUAGE FunctionalDependencies, MultiParamTypeClasses #-}
23 module Control.Monad.State.Class (
30 -- ---------------------------------------------------------------------------
31 -- | /get/ returns the state from the internals of the monad.
33 -- /put/ replaces the state inside the monad.
35 class (Monad m) => MonadState s m | m -> s where
39 -- | Monadic state transformer.
41 -- Maps an old state to a new state inside a state monad.
42 -- The old state is thrown away.
44 -- > Main> :t modify ((+1) :: Int -> Int)
45 -- > modify (...) :: (MonadState Int a) => a ()
47 -- This says that @modify (+1)@ acts over any
48 -- Monad that is a member of the @MonadState@ class,
49 -- with an @Int@ state.
51 modify :: (MonadState s m) => (s -> s) -> m ()
56 -- | Gets specific component of the state, using a projection function
59 gets :: (MonadState s m) => (s -> a) -> m a