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
- 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
- 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
- tagCont' :: forall new m a. Via (Cont' G) (Tagger G new) m a -> m a
- retagCont' :: forall tag new m a. Via (Cont' tag) (Tagger tag new) m a -> m a
- untagCont' :: forall tag m a. Via (Cont' tag) (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.
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
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.
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'
.
Tagging and Untagging
Conversion functions between the tagged and untagged continuation effect, usually used in combination with type applications, like:
tagCont'
@"newTag" programretagCont'
@"oldTag" @"newTag" programuntagCont'
@"erasedTag" program