A function that runs a transformed monad T
n on the monadic state that
was captured by liftWith
A function that runs a transformed monad T
n on the monadic state that
was captured by liftWith
A Run
function yields a computation in M
that returns the monadic state
of T
. This state can later be used to restore a T
computation using
restoreT
.
Monadic state of T
.
liftWith
is similar to liftM
in that it lifts a computation from the
argument monad to the constructed monad.
liftWith
is similar to liftM
in that it lifts a computation from the
argument monad to the constructed monad.
Instances should satisfy similar laws as the MonadTrans
laws:
liftWith . const . return = return liftWith (const (m >>= f)) = liftWith (const m) >>= liftWith . const . f
The difference with liftM
is that before lifting the M
computation
liftWith
captures the state of T
. It then provides the M
computation
with a Run
function that allows running T[M, ?]
computations in M
(for all M
) on the captured state.
Construct a T
computation from the monadic state of T
that is returned
from a Run
function.
Construct a T
computation from the monadic state of T
that is returned
from a Run
function.
Instances should satisfy:
liftWith (\run -> run t) >>= restoreT . return = t
An often used composition: control f = liftWith f >>= restoreT . return