Copyright | (c) Michael Szvetits 2020 |
---|---|

License | BSD3 (see the file LICENSE) |

Maintainer | typedbyte@qualified.name |

Stability | stable |

Portability | portable |

Safe Haskell | None |

Language | Haskell2010 |

The continuation effect, similar to the `MonadCont`

type class from the
`mtl`

library.

## Synopsis

- class Monad m => Cont' tag m where
- callCC' :: ((a -> m b) -> m a) -> m a

- type Cont = Cont' G
- callCC :: Cont m => ((a -> m b) -> m a) -> m a
- evalCont' :: forall tag r m. Applicative m => (Cont' tag `Via` ContT r) m r -> m r
- evalCont :: Applicative m => (Cont `Via` ContT r) m r -> m r
- runCont' :: forall tag r m a. (a -> m r) -> (Cont' tag `Via` ContT r) m a -> m r
- runCont :: (a -> m r) -> (Cont `Via` ContT r) m a -> m r
- tagCont' :: forall new m a. (Cont' G `Via` Tagger G new) m a -> m a
- retagCont' :: forall tag new m a. (Cont' tag `Via` Tagger tag new) m a -> m a
- untagCont' :: forall tag m a. (Cont' tag `Via` Tagger tag G) m a -> m a

# Tagged Continuation Effect

class Monad m => Cont' tag m where Source #

An effect that adds an abortive continuation to a computation.

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

Adapted from the `mtl`

library documentation:

`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 result to `throwError'`

and
`catchError'`

of the `Error'`

effect. Advantage of this function over calling `return`

is that it makes
the continuation explicit, allowing more flexibility and better control.

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.

#### Instances

Handle '[Monad] (Cont' tag) others t m => Cont' (tag :: k) (EachVia (Cont' tag ': others) t m) Source # | |

Find '[Monad] (Cont' tag) other effs t m => Cont' (tag :: k) (EachVia (other ': effs) t m) Source # | |

Cont' (tag :: k1) (ContT r m) Source # | |

Control ('[] :: [Effect]) (Cont' tag) t m => Cont' (tag :: k) (EachVia ('[] :: [Effect]) t m) Source # | |

Cont' new m => Cont' (tag :: k2) (Tagger tag new m) Source # | |

# Untagged Continuation Effect

If you don't require disambiguation of multiple continuation effects (i.e., you only have one continuation effect in your monadic context), it is recommended to always use the untagged continuation effect.

# Interpretations

evalCont' :: forall tag r m. Applicative m => (Cont' tag `Via` ContT r) m r -> m r Source #

Runs the continuation effect with `pure`

as final continuation.

evalCont :: Applicative m => (Cont `Via` ContT r) m r -> m r Source #

The untagged version of `evalCont'`

.

runCont' :: forall tag r m a. (a -> m r) -> (Cont' tag `Via` ContT r) m a -> m r Source #

Runs the continuation effect with a given final continuation.

# Tagging and Untagging

Conversion functions between the tagged and untagged continuation effect, usually used in combination with type applications, like:

`tagCont'`

@"newTag" program`retagCont'`

@"oldTag" @"newTag" program`untagCont'`

@"erasedTag" program