state package:fused-effects

Compute a new state and a value in a single step.
state f = gets f >>= \ (s, a) -> put s >> pure a
An effect that adds a mutable, updatable state value to a given computation. Not all computations require a full-fledged state effect: read-only state is better served by Reader, and append-only state without reads is better served by Writer. Predefined carriers:
Interpret an effect using a higher-order function with some state variable.
Run a State effect, yielding the result value and discarding the final state.
evalState = runState (const pure)
Run a State effect, yielding the final state and discarding the return value.
execState = runState (const . pure)
Run a State effect starting from the passed value, applying a continuation to the final state and result.
runState k s (pure a) = k s a
runState k s get = k s s
runState k s (put t) = k t ()
Run a State effect, yielding the result value and discarding the final state.
evalState s m = fmap snd (runState s m)
Run a State effect, yielding the final state and discarding the return value.
execState s m = fmap fst (runState s m)
Run a State effect starting from the passed value.
runState s (pure a) = pure (s, a)
runState s get = pure (s, s)
runState s (put t) = pure (t, ())
Run a State effect starting from the passed IORef. This function is lawless, given that the underlying IORef can be modified by another thread.
Run a lazy State effect, yielding the result value and discarding the final state.
evalState s m = fmap snd (runState s m)
Run a lazy State effect, yielding the final state and discarding the return value.
execState s m = fmap fst (runState s m)
Run a lazy State effect, yielding the result value and the final state. More programs terminate with lazy state than strict state, but injudicious use of lazy state may lead to thunk buildup.
runState s (pure a) = pure (s, a)
runState s get = pure (s, s)
runState s (put t) = pure (t, ())
Run a State effect, yielding the result value and discarding the final state.
evalState s m = fmap snd (runState s m)
Run a State effect, yielding the final state and discarding the return value.
execState s m = fmap fst (runState s m)
Run a State effect starting from the passed value.
runState s (pure a) = pure (s, a)
runState s get = pure (s, s)
runState s (put t) = pure (t, ())