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

Safe HaskellNone
LanguageHaskell2010

Control.Effect.State

Synopsis

Documentation

class MemberEffect State (State s) l => EffectState s l Source

Instances

MemberEffect (* -> * -> *) State (State s) l => EffectState s l 

data State s a Source

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

Instances

type Is (* -> * -> *) State f 

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

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

evalState :: s -> Effect (State s :+ l) a -> Effect l a Source

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

execState :: s -> Effect (State s :+ l) a -> Effect l s Source

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

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

Gets the current state.

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

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

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

Replaces the current state.

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

Applies a pure modifier to the state value.

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

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

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

Lifts a stateful computation to the Effect monad.

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

Runs a computation with a modified state value.

withState f x = modify f >> x