Run an
State effect in terms of operations in
ST.
Internally, this simply creates a new
STRef, passes it to
runStateSTRef, and then returns the result and the final value
of the
STRef.
Beware: As this uses an
STRef internally, all other
effects will have local state semantics in regards to
State
effects interpreted this way. For example,
throw and
catch will never revert
puts, even if
runError is
used after
stateToST.
When not using the plugin, one must introduce the existential
st type to
stateToST, so that the resulting type after
runM can be resolved into
forall st. ST st (s, a) for
use with
runST. Doing so requires
-XScopedTypeVariables.
stResult :: forall s a. (s, a)
stResult = runST ( (runM $ stateToST @_ @st undefined $ pure undefined) :: forall st. ST st (s, a) )