Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Algebraic effects and named handlers
Variant of Bluefin.Algae using dynamic exceptions to cancel continuations.
Synopsis
- type AEffect = Type -> Type
- type HandlerBody ex f ss a = forall x ss0. ex :> ss0 => f x -> Continuation ss0 ss x a -> Eff ss a
- data Handler ex f s
- handle :: h ex -> HandlerBody ex f ss a -> (forall s. Handler ex f s -> Eff (s :& ss) a) -> Eff ss a
- call :: (ex :> es, s :> es) => Handler ex f s -> f a -> Eff es a
- continue :: Continuation t s b a -> b -> Eff s a
- discontinue :: (Exception e, ex :> es0) => DynExn ex -> Continuation es0 es b a -> e -> Eff es a
- discontinueIO :: (Exception e, io :> es0) => IOE io -> Continuation es0 es b a -> e -> Eff es a
- cancel :: (ex :> es0, ex :> es) => DynExn ex -> Continuation es0 es b a -> Eff es ()
- data CancelContinuation = CancelContinuation
Documentation
type HandlerBody ex f ss a = forall x ss0. ex :> ss0 => f x -> Continuation ss0 ss x a -> Eff ss a Source #
Interpretation of an algebraic effect f
: a function to handle the operations of f
with cancellable continuations.
Handler to call operations of the effect f
with cancellable continuations.
handle :: h ex -> HandlerBody ex f ss a -> (forall s. Handler ex f s -> Eff (s :& ss) a) -> Eff ss a Source #
call :: (ex :> es, s :> es) => Handler ex f s -> f a -> Eff es a Source #
Call an operation of f
with cancellable continuations.
continue :: Continuation t s b a -> b -> Eff s a Source #
Resume a cancellable continuation with a result.
In other words, this converts a cancellable continuation to a simple continuation.
discontinue :: (Exception e, ex :> es0) => DynExn ex -> Continuation es0 es b a -> e -> Eff es a Source #
Resume by throwing a dynamic exception.
Note that different outcomes are possible depending on your handled computation. Be sure to handle them appropriately.
- A common situation is that the continuation will rethrow the initial exception,
then you can just catch it (or use
cancel
). - The continuation may throw a different exception, so you should be careful to catch the right exception.
- The continuation may also catch your exception and terminate normally
with a result of type
a
.
discontinueIO :: (Exception e, io :> es0) => IOE io -> Continuation es0 es b a -> e -> Eff es a Source #
Specialization of discontinue
to IOE
.
cancel :: (ex :> es0, ex :> es) => DynExn ex -> Continuation es0 es b a -> Eff es () Source #
discontinue
a continuation with the CancelContinuation
exception and catch it when it
is re-thrown by the continuation.
The continuation SHOULD re-throw CancelContinuation
if it catches it.
data CancelContinuation Source #
Exception thrown by cancel
.
Instances
Exception CancelContinuation Source # | |
Defined in Bluefin.Algae.DynExn | |
Show CancelContinuation Source # | |
Defined in Bluefin.Algae.DynExn showsPrec :: Int -> CancelContinuation -> ShowS # show :: CancelContinuation -> String # showList :: [CancelContinuation] -> ShowS # |