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

Safe HaskellNone
LanguageHaskell2010

Control.Effect.State

Synopsis

Documentation

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

Instances

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

data State s a

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

Instances

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

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

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

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

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

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

get :: EffectState s l => Effect l s

Gets the current state.

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

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

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

Replaces the current state.

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

Applies a pure modifier to the state value.

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

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

Lifts a stateful computation to the Effect monad.

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

Runs a computation with a modified state value.

withState f x = modify f >> x