simple-effects-0.9.0.1: A simple effect system that integrates with MTL

Safe HaskellNone
LanguageHaskell2010

Control.Effects.State

Description

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_.

Synopsis

Documentation

data State s Source #

Constructors

Get 
Set 

Instances

Monad m => MonadEffect (State * s) (StateT s m) Source # 

Methods

effect :: Effect (State * s) method Msg -> StateT s m (Effect (State * s) method Res) Source #

data Effect (State k s) Source # 
data Effect (State k s) where

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.