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 -----------------------------------------------------------------------------
22 module Control.Monad.State.Class (
29 -- ---------------------------------------------------------------------------
30 -- | /get/ returns the state from the internals of the monad.
32 -- /put/ replaces the state inside the monad.
34 class (Monad m) => MonadState s m | m -> s where
38 -- | Monadic state transformer.
40 -- Maps an old state to a new state inside a state monad.
41 -- The old state is thrown away.
43 -- > Main> :t modify ((+1) :: Int -> Int)
44 -- > modify (...) :: (MonadState Int a) => a ()
46 -- This says that @modify (+1)@ acts over any
47 -- Monad that is a member of the @MonadState@ class,
48 -- with an @Int@ state.
50 modify :: (MonadState s m) => (s -> s) -> m ()
55 -- | Gets specific component of the state, using a projection function
58 gets :: (MonadState s m) => (s -> a) -> m a