Safe Haskell | None |
---|---|
Language | Haskell2010 |
The MonadState
you know and love with some differences. First, there's no functional
dependency limiting your stack to a single state type. This means less type inference so
it might not be enough to just write getState
. Write 'getState @MyStateType' instead using
TypeApplications.
Second, the functions have less generic names and are called getState
and setState
.
Third, since it's a part of this effect framework, you get a handleState
function with
which you can provide a different state implementation _at runtime_.
- data State s
- getState :: forall s m. MonadEffect (State s) m => m s
- setState :: forall s m. MonadEffect (State s) m => s -> m ()
- modifyState :: forall s m. MonadEffect (State s) m => (s -> s) -> m ()
- handleState :: forall m s a. Monad m => m s -> (s -> m ()) -> EffectHandler (State s) m a -> m a
- handleStateIO :: MonadIO m => s -> EffectHandler (State s) m a -> m a
- handleStateT :: Monad m => s -> StateT s m a -> m a
- module Control.Effects
Documentation
getState :: forall s m. MonadEffect (State s) m => m s Source #
setState :: forall s m. MonadEffect (State s) m => s -> m () Source #
modifyState :: forall s m. MonadEffect (State s) m => (s -> s) -> m () Source #
handleState :: forall m s a. Monad m => m s -> (s -> m ()) -> EffectHandler (State s) m a -> m a Source #
Handle the 'MonadEffect (State s)' constraint by providing custom handling functions.
handleStateIO :: MonadIO m => s -> EffectHandler (State s) m a -> m a Source #
Handle the state requirement using an IORef
.
handleStateT :: Monad m => s -> StateT s m a -> m a Source #
Handle the state requirement using the standard StateT
transformer.
module Control.Effects