unliftIO package:resourcet

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:
  • unliftIO u . return = return
  • unliftIO u (m >>= f) = unliftIO u m >>= unliftIO
    u . f
Instances of MonadUnliftIO must also satisfy the idempotency law:
  • askUnliftIO >>= \u -> (liftIO . unliftIO u) m =
    m
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.