Safe Haskell | None |
---|---|

Language | Haskell2010 |

This module is a duplication of the Control.Monad.Cont module, from the mtl.

- class Monad m => MonadCont m where
- newtype ContT k r m a :: forall k. k -> (k -> *) -> * -> * = ContT {
- runContT :: (a -> m r) -> m r

- cont :: ((a -> r) -> r) -> Cont r a
- mapContT :: (m r -> m r) -> ContT k r m a -> ContT k r m a
- withContT :: ((b -> m r) -> a -> m r) -> ContT k r m a -> ContT k r m b
- runCont :: Cont r a -> (a -> r) -> r
- mapCont :: (r -> r) -> Cont r a -> Cont r a
- withCont :: ((b -> r) -> a -> r) -> Cont r a -> Cont r b

# Documentation

class Monad m => MonadCont m where Source #

A class for monads which can embed continuations.

callCC :: ((a -> m b) -> m a) -> m a Source #

`callCC`

(call-with-current-continuation)
calls a function with the current continuation as its argument.
Provides an escape continuation mechanism for use with Continuation monads.
Escape continuations allow to abort the current computation and return
a value immediately.
They achieve a similar effect to `throwError`

and `catchError`

within an `Error`

monad.
Advantage of this function over calling `return`

is that it makes
the continuation explicit,
allowing more flexibility and better control
(see examples in Control.Monad.Cont).

The standard idiom used with `callCC`

is to provide a lambda-expression
to name the continuation. Then calling the named continuation anywhere
within its scope will escape from the computation,
even if it is many layers deep within nested computations.

(MonadCont m, Monad (Unconstrained m)) => MonadCont (MaybeT m) Source # | |

MonadCont m => MonadCont (IdentityT * m) Source # | |

(MonadCont m, Monad (Unconstrained m)) => MonadCont (ExceptT e m) Source # | |

(MonadCont m, Monad (Unconstrained m)) => MonadCont (StateT s m) Source # | |

(MonadCont m, Monad (Unconstrained m)) => MonadCont (StateT s m) Source # | |

MonadCont (ContT * r m) Source # | |

MonadCont m => MonadCont (ReaderT * r m) Source # | |

newtype ContT k r m a :: forall k. k -> (k -> *) -> * -> * #

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.

MonadReader r' m => MonadReader r' (ContT * r m) Source # | |

(MonadState s m, Suitable m r) => MonadState s (ContT * r m) Source # | |

MonadTrans (ContT * r) | |

MonadTrans (ContT * r) Source # | |

Monad (ContT k r m) | |

Functor (ContT k r m) | |

MonadFail m => MonadFail (ContT * r m) | |

Applicative (ContT k r m) | |

MonadIO m => MonadIO (ContT * r m) | |

Monad (ContT * r m) Source # | |

Applicative (ContT * r m) Source # | |

Functor (ContT * r m) Source # | |

Monad (ContT * r m) Source # | |

MonadCont (ContT * r m) Source # | |

MonadIO m => MonadIO (ContT * r m) Source # | |

type SuitableLift (ContT * r) m a Source # | |

type Unconstrained (ContT * r m) Source # | |

type Suitable (ContT * r m) a Source # | |

type Suitable (ContT * r m) a Source # | |

type SuitableIO (ContT * r m) a Source # | |

type ReaderSuitable (ContT * r m) a Source # | |

type StateSuitable (ContT * r m) a Source # | |

cont :: ((a -> r) -> r) -> Cont r a #

Construct a continuation-passing computation from a function.
(The inverse of `runCont`

)

:: Cont r a | continuation computation ( |

-> (a -> r) | the final continuation, which produces
the final result (often |

-> r |

The result of running a CPS computation with a given final continuation.
(The inverse of `cont`

)