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

Bluefin.Algae.Exception

Description

Exceptions as an algebraic effect

These scoped exceptions are similar to Bluefin.Exception.

Algebraic operations in Bluefin are truly scoped: they cannot be intercepted by exception handlers, notably bracket.

catch and try make an explicit call to cancel to trigger exception handlers. This makes them equivalent to Bluefin.Exception.

The simpler variants catch' and try' don't use cancel, so they are faster when there is no bracket to worry about.

Synopsis

Operations

data Exception (e :: Type) :: AEffect where Source #

Exception interface.

Constructors

Throw :: e -> Exception e r

Throw an exception.

throw :: z :> zz => Handler (Exception e) z -> e -> Eff zz a Source #

Throw an exception. Call the Throw operation.

Default handlers

catch :: forall e a zz. (forall z. Handler (Exception e) z -> Eff (z :& zz) a) -> (e -> Eff zz a) -> Eff zz a Source #

Catch an exception.

The continuation is canceled (cancel) when an exception is thrown to this handler.

try :: forall e a zz. (forall z. Handler (Exception e) z -> Eff (z :& zz) a) -> Eff zz (Either e a) Source #

Return Either the exception or the result of the handled computation.

The continuation is canceled (cancel) when an exception is thrown to this handler.

Variant without cancelling continuations

catch' Source #

Arguments

:: forall e a zz. (forall z. Handler (Exception e) z -> Eff (z :& zz) a)

Handled computation

-> (e -> Eff zz a)

Exception clause

-> Eff zz a 

Catch an exception.

Simple version of catch which just discards the continuation instead of explicitly cancelling it.

Warning: Discarded continuations

catch' discards the continuation, which may be problematic if there are resources to be freed by the continuation (typically if throw was called in the middle of a bracket). Use catch to free those resources instead.

Without anything like bracket, catch' does less work. catch makes throw traverse the stack twice (first to find the prompt, then to cancel the continuation). catch' makes throw traverse the stack only once.

try' :: forall e a zz. (forall z. Handler (Exception e) z -> Eff (z :& zz) a) -> Eff zz (Either e a) Source #

Return Either the exception or the result of the handled computation.

Simple version of try which discards the continuation (like catch').