License | BSD-style (see the file LICENSE) |
---|---|
Maintainer | ocean0yohsuke@gmail.com |
Stability | experimental |
Portability | --- |
Safe Haskell | Safe |
Language | Haskell2010 |
This module is just a concise mimic for State Monad in mtl(monad-transformer-library).
The qualifier "concise" means that this module doesn't make no attempt to transform functions of any kind of Monad automatically.
So when making some new data type of StateT, you have to manually define involved Monad instances,
for example MonadError
,
by making use of the transformation functions such as trans
, trans2
, etc.
Admittedly it is tedious though, you can deeply understand monad-transformation mechanism instead.
- class Monad m => MonadState s m | m -> s where
- modify :: MonadState s m => (s -> s) -> m ()
- gets :: MonadState s m => (s -> a) -> m a
- newtype State s a = State {
- runState :: s -> (a, s)
- evalState :: State s a -> s -> a
- execState :: State s a -> s -> s
- mapState :: ((a, s) -> (b, s)) -> State s a -> State s b
- withState :: (s -> s) -> State s a -> State s a
- newtype StateT s m a = StateT {
- runStateT :: s -> m (a, s)
- evalStateT :: Monad m => StateT s m a -> s -> m a
- execStateT :: Monad m => StateT s m a -> s -> m s
- mapStateT :: (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b
- withStateT :: (s -> s) -> StateT s m a -> StateT s m a
- liftCatch :: Catch e m (a, s) -> Catch e (StateT s m) a
- newtype StateT2 s m1 m2 a = StateT2 {
- runStateT2 :: s -> m1 (m2 (a, s))
- evalStateT2 :: (Monad m1, Monad2 m2) => StateT2 s m1 m2 a -> s -> m1 (m2 a)
- execStateT2 :: (Monad m1, Monad2 m2) => StateT2 s m1 m2 a -> s -> m1 (m2 s)
- mapStateT2 :: (m1 (m2 (a, s)) -> n1 (n2 (b, s))) -> StateT2 s m1 m2 a -> StateT2 s n1 n2 b
- withStateT2 :: (s -> s) -> StateT2 s m1 m2 a -> StateT2 s m1 m2 a
- newtype StateT3 s m1 m2 m3 a = StateT3 {
- runStateT3 :: s -> m1 (m2 (m3 (a, s)))
- evalStateT3 :: (Monad m1, Monad2 m2, Monad3 m3) => StateT3 s m1 m2 m3 a -> s -> m1 (m2 (m3 a))
- execStateT3 :: (Monad m1, Monad2 m2, Monad3 m3) => StateT3 s m1 m2 m3 a -> s -> m1 (m2 (m3 s))
- mapStateT3 :: (m1 (m2 (m3 (a, s))) -> n1 (n2 (n3 (b, s)))) -> StateT3 s m1 m2 m3 a -> StateT3 s n1 n2 n3 b
- withStateT3 :: (s -> s) -> StateT3 s m1 m2 m3 a -> StateT3 s m1 m2 m3 a
Documentation
class Monad m => MonadState s m | m -> s where
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 () Source
gets :: MonadState s m => (s -> a) -> m a Source
Level-0
Level-1
evalStateT :: Monad m => StateT s m a -> s -> m a Source
execStateT :: Monad m => StateT s m a -> s -> m s Source
withStateT :: (s -> s) -> StateT s m a -> StateT s m a Source
Level-2
newtype StateT2 s m1 m2 a Source
StateT2 | |
|
(Monad m1, Monad2 m2) => MonadState s (StateT2 s m1 m2) Source | |
MonadTrans2 (StateT2 s) Source | |
(Monad m1, Monad2 m2) => Monad (StateT2 s m1 m2) Source | |
(Functor m1, Functor m2) => Functor (StateT2 s m1 m2) Source | |
(Monad m1, Monad2 m2) => Applicative (StateT2 s m1 m2) Source | |
(MonadIO m1, Monad m1, Monad2 m2) => MonadIO (StateT2 s m1 m2) Source |
evalStateT2 :: (Monad m1, Monad2 m2) => StateT2 s m1 m2 a -> s -> m1 (m2 a) Source
execStateT2 :: (Monad m1, Monad2 m2) => StateT2 s m1 m2 a -> s -> m1 (m2 s) Source
mapStateT2 :: (m1 (m2 (a, s)) -> n1 (n2 (b, s))) -> StateT2 s m1 m2 a -> StateT2 s n1 n2 b Source
withStateT2 :: (s -> s) -> StateT2 s m1 m2 a -> StateT2 s m1 m2 a Source
Level-3
newtype StateT3 s m1 m2 m3 a Source
StateT3 | |
|
(Monad m1, Monad2 m2, Monad3 m3) => MonadState s (StateT3 s m1 m2 m3) Source | |
MonadTrans3 (StateT3 s) Source | |
(Monad m1, Monad2 m2, Monad3 m3) => Monad (StateT3 s m1 m2 m3) Source | |
(Functor m1, Functor m2, Functor m3) => Functor (StateT3 s m1 m2 m3) Source | |
(Monad m1, Monad2 m2, Monad3 m3) => Applicative (StateT3 s m1 m2 m3) Source | |
(MonadIO m1, Monad m1, Monad2 m2, Monad3 m3) => MonadIO (StateT3 s m1 m2 m3) Source |
evalStateT3 :: (Monad m1, Monad2 m2, Monad3 m3) => StateT3 s m1 m2 m3 a -> s -> m1 (m2 (m3 a)) Source
execStateT3 :: (Monad m1, Monad2 m2, Monad3 m3) => StateT3 s m1 m2 m3 a -> s -> m1 (m2 (m3 s)) Source
mapStateT3 :: (m1 (m2 (m3 (a, s))) -> n1 (n2 (n3 (b, s)))) -> StateT3 s m1 m2 m3 a -> StateT3 s n1 n2 n3 b Source
withStateT3 :: (s -> s) -> StateT3 s m1 m2 m3 a -> StateT3 s m1 m2 m3 a Source