Safe Haskell | None |
---|---|

Language | Haskell2010 |

This module duplicates the Control.Monad.State module from mtl for monads with constraints.

- class Monad m => MonadState s m | m -> s where
- type StateSuitable m a :: Constraint

- newtype StateT s m a :: * -> (* -> *) -> * -> * = StateT {
- runStateT :: s -> m (a, s)

- gets :: (StateSuitable m s, MonadState s m, Suitable m b) => (s -> b) -> m b
- modify :: (StateSuitable m (), StateSuitable m s, MonadState s m) => (s -> s) -> m ()
- modify' :: (StateSuitable m (), StateSuitable m s, MonadState s m) => (s -> s) -> m ()

# Documentation

class Monad m => MonadState s m | m -> s where Source #

A class for monads with state.

type StateSuitable m a :: Constraint Source #

get :: StateSuitable m s => m s Source #

Return the state from the internals of the monad.

put :: (StateSuitable m (), StateSuitable m s) => s -> m () Source #

Replace the state inside the monad.

state :: (StateSuitable m a, StateSuitable m s) => (s -> (a, s)) -> m a Source #

Embed a simple state action in the monad.

(MonadState s m, Monad (Unconstrained m)) => MonadState s (MaybeT m) Source # | |

(MonadState s m, Monad (Unconstrained m)) => MonadState s (ExceptT e m) Source # | |

MonadState s m => MonadState s (IdentityT * m) Source # | |

(Monad m, Monad (Unconstrained m)) => MonadState s (StateT s m) Source # | |

(Monad m, Monad (Unconstrained m)) => MonadState s (StateT s m) Source # | |

(MonadState s m, Monad (Unconstrained m)) => MonadState s (WriterT w m) Source # | |

MonadState s m => MonadState s (ReaderT * r m) Source # | |

(MonadState s m, Suitable m r) => MonadState s (ContT * r m) Source # | |

newtype StateT s m a :: * -> (* -> *) -> * -> * #

A state transformer monad parameterized by:

`s`

- The state.`m`

- The inner monad.

The `return`

function leaves the state unchanged, while `>>=`

uses
the final state of the first computation as the initial state of
the second.

gets :: (StateSuitable m s, MonadState s m, Suitable m b) => (s -> b) -> m b Source #

Get the state, while applying a transformation function.

modify :: (StateSuitable m (), StateSuitable m s, MonadState s m) => (s -> s) -> m () Source #

Modify the state.

modify' :: (StateSuitable m (), StateSuitable m s, MonadState s m) => (s -> s) -> m () Source #

Modify the state, strictly in the new state.