runState -package:random

Unwrap a state monad computation as a function. (The inverse of state.)
Run a State effect with local state.
Unwrap a state monad computation as a function. (The inverse of state.)
Run the State effect with the given initial state and return the final value along with the final state.
Encapsulation of a state-using computation, exposing the initial and final states. Typical usage in arrow notation:
proc p -> do
...
(result, final_state) <- (|runState cmd|) init_state
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 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 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 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 with local state.
>>> runPureEff $ runState 10 $ \st -> do
n <- get st
pure (2 * n)
(20,10)
Interpret the State effect.
This is the state record that controls the output style.
Run StateT in the base monad Since 1.0.11
Run StateT in the base monad Since 1.0.11
Run StateT in the base monad
Run a State effect by transforming it into operations over an IORef. Note: This is not safe in a concurrent setting, as modify isn't atomic. If you need operations over the state to be atomic, use runAtomicStateIORef or runAtomicStateTVar instead.