bluefin-algae-0.1.0.1: Algebraic effects and named handlers in Bluefin.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Bluefin.Algae.DynExn

Description

Algebraic effects and named handlers

Variant of Bluefin.Algae using dynamic exceptions to cancel continuations.

Synopsis

Documentation

type AEffect = Type -> Type Source #

Algebraic effect.

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.

data Handler ex f s Source #

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 #

Handle operations of f with cancellable continuations.

The handle for exceptions (first argument) is only there to guide type inference. it can be either IOE or DynExn.

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.