runState

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.)
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 the State effect with the given initial state and return the final value along with the final state.
Run a State effect
Run a State effect
Run a State effect with local state.
Run the State effect.

Caveats

The runState interpreter is implemented with IORefs and there is no way to do arbitrary atomic transactions. The state operation is atomic though and it is implemented with atomicModifyIORefCAS, which can be faster than atomicModifyIORef in contention. For any more complicated cases of atomicity, please build your own effect that uses either MVars or TVars based on your need. Unlike mtl, in cleff the state will not revert when an error is thrown. runState will stop taking care of state operations done on forked threads as soon as the main thread finishes its computation. Any state operation done before main thread finishes is still taken into account.
This is the state record that controls the output style.
Runs a monadic generating action in the State monad using a pure pseudo-random number generator.

Examples

>>> import System.Random.Stateful

>>> let pureGen = mkStdGen 137

>>> runStateGen pureGen randomM :: (Int, StdGen)
(7879794327570578227,StdGen {unStdGen = SMGen 11285859549637045894 7641485672361121627})
Runs a monadic generating action in the ST monad using a pure pseudo-random number generator.
Runs a monadic generating action in the ST monad using a pure pseudo-random number generator. Same as runStateGenST, but discards the resulting generator.
Runs a monadic generating action in the StateT monad using a pure pseudo-random number generator.

Examples

>>> import System.Random.Stateful

>>> let pureGen = mkStdGen 137

>>> runStateGenT pureGen randomM :: IO (Int, StdGen)
(7879794327570578227,StdGen {unStdGen = SMGen 11285859549637045894 7641485672361121627})