Monads which allow their actions to be run in
IO.
While
MonadIO allows an
IO action to be lifted into
another monad, this class captures the opposite concept: allowing you
to capture the monadic context. Note that, in order to meet the laws
given below, the intuition is that a monad must have no monadic state,
but may have monadic context. This essentially limits
MonadUnliftIO to
ReaderT and
IdentityT
transformers on top of
IO.
Laws. For any value
u returned by
askUnliftIO, it must
meet the monad transformer laws as reformulated for
MonadUnliftIO:
Instances of
MonadUnliftIO must also satisfy the idempotency
law:
This law showcases two properties. First,
askUnliftIO doesn't
change the monadic context, and second,
liftIO . unliftIO u
is equivalent to
id IF called in the same monadic context as
askUnliftIO.