Cont module:Control.Monad.Trans

Continuation monads. Delimited continuation operators are taken from Kenichi Asai and Oleg Kiselyov's tutorial at CW 2011, "Introduction to programming with shift and reset" (http://okmij.org/ftp/continuations/#tutorial).
The continuation monad, which is non-strict. Cont r a is a CPS ("continuation-passing style") computation that produces an intermediate result of type a within a CPS computation whose final result type is r. The return function simply creates a continuation which passes the value on. The >>= operator adds the bound function into the continuation chain.
The continuation indexed monad transformer.
Construct a continuation-passing computation from a function. (The inverse of runCont)
The continuation monad transformer. Can be used to add continuation handling to any type constructor: the Monad instance and most of the operations do not require m to be a monad. ContT is not a functor on the category of monads, and many operations cannot be lifted through it. ContT r m is strict if and only if m is.
This module defines the type class MonadBaseControl, a subset of MonadBase into which generic control operations such as catch can be lifted from IO or any other base monad. Instances are based on monad transformers in MonadTransControl, which includes all standard monad transformers in the transformers library except ContT. See the lifted-base package which uses monad-control to lift IO operations from the base library (like catch or bracket) into any monad that is an instance of MonadBase or MonadBaseControl. See the following tutorial by Michael Snoyman on how to use this package: https://www.yesodweb.com/book/monad-control

Quick implementation guide

Given a base monad B and a stack of transformers T:
Cont r ~ Contravariant.Adjoint (Op r) (Op r)
Conts r ~ Contravariant.AdjointT (Op r) (Op r)
ContsT r w m ~ Contravariant.AdjointT (Op (m r)) (Op (m r)) w
An often used composition: control f = liftBaseWith f >>= restoreM Example:
liftedBracket :: MonadBaseControl IO m => m a -> (a -> m b) -> (a -> m c) -> m c
liftedBracket acquire release action = control $ \runInBase ->
bracket (runInBase acquire)
(\saved -> runInBase (restoreM saved >>= release))
(\saved -> runInBase (restoreM saved >>= action))
Lift a computation and restore the monadic state immediately: controlT f = liftWith f >>= restoreT . return.