effin-0.1.0.0: A Typeable-free implementation of extensible effects

Safe HaskellNone
LanguageHaskell2010

Control.Effect.State

Synopsis

Documentation

type EffectState s es = (Member (State s) es, s ~ StateType es) Source

data State s a Source

An effect where a state value is threaded throughout the computation.

Instances

runState :: s -> Effect (State s : es) a -> Effect es (a, s) Source

Completely handles a State effect by providing an initial state, and making the final state explicit.

evalState :: s -> Effect (State s : es) a -> Effect es a Source

Completely handles a State effect, and discards the final state.

execState :: s -> Effect (State s : es) a -> Effect es s Source

Completely handles a State effect, and discards the final value.

get :: EffectState s es => Effect es s Source

Gets the current state.

gets :: EffectState s es => (s -> a) -> Effect es a Source

Gets a value that is a function of the current state.

put :: EffectState s es => s -> Effect es () Source

Replaces the current state.

modify :: EffectState s es => (s -> s) -> Effect es () Source

Applies a pure modifier to the state value.

modify' :: EffectState s es => (s -> s) -> Effect es () Source

Applies a pure modifier to the state value. The modified value is converted to weak head normal form.

state :: EffectState s es => (s -> (a, s)) -> Effect es a Source

Lifts a stateful computation to the Effect monad.

withState :: EffectState s es => (s -> s) -> Effect es a -> Effect es a Source

Runs a computation with a modified state value.

withState f x = modify f >> x