| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
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
- data Exception (e :: Type) :: AEffect where
- throw :: z :> zz => Handler (Exception e) z -> e -> Eff zz a
- catch :: forall e a zz. (forall z. Handler (Exception e) z -> Eff (z :& zz) a) -> (e -> Eff zz a) -> Eff zz a
- try :: forall e a zz. (forall z. Handler (Exception e) z -> Eff (z :& zz) a) -> Eff zz (Either e a)
- catch' :: forall e a zz. (forall z. Handler (Exception e) z -> Eff (z :& zz) a) -> (e -> Eff zz a) -> Eff zz a
- try' :: forall e a zz. (forall z. Handler (Exception e) z -> Eff (z :& zz) a) -> Eff zz (Either e a)
Operations
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 #
Variant without cancelling continuations
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.