Error utilities

- catchErrorJust :: MonadError e m => (e -> Maybe b) -> m a -> (b -> m a) -> m a
- handleError :: MonadError e m => (e -> m a) -> m a -> m a
- handleErrorJust :: MonadError e m => (e -> Maybe b) -> (b -> m a) -> m a -> m a
- tryError :: MonadError e m => m a -> m (Either e a)
- tryErrorJust :: MonadError e m => (e -> Maybe b) -> m a -> m (Either b a)
- finallyError :: MonadError e m => m a -> m b -> m a
- bracketError :: MonadError e m => m a -> (a -> m b) -> (a -> m c) -> m c
- bracketError_ :: MonadError e m => m a -> m b -> m c -> m c

# Documentation

:: MonadError e m | |

=> (e -> Maybe b) | Decider function |

-> m a | Monad |

-> (b -> m a) | Handler function |

-> m a | Result: A monadic operation on type a |

`catchErrorJust`

is an error catcher for the Maybe type. As input is given
a deciding function, a monad and a handler. When an error is caught, the
decider is executed to decide if the error should be handled or not.
Then the handler is eventually called to handle the error.

:: MonadError e m | |

=> (e -> m a) | Error handler |

-> m a | Monad |

-> m a | Resulting monad |

`handleError`

is the flipped version of `catchError`

.

:: MonadError e m | |

=> (e -> Maybe b) | Decider |

-> (b -> m a) | Handler |

-> m a | Monad |

-> m a | Resulting Monad |

`handleErrorJust`

is the flipped version of `catchErrorJust`

.

:: MonadError e m | |

=> m a | Monad to operate on |

-> m (Either e a) | Returns: Explicit Either type |

`tryError`

uses Either to explicitly define the outcome of a
monadic operation. An error is caught and placed into Right,
whereas successful operation is placed into Left.

:: MonadError e m | |

=> (e -> Maybe b) | Decider |

-> m a | Monad |

-> m (Either b a) | Returns: Explicit Either type |

`tryErrorJust`

is the `catchErrorJust`

version of `tryError`

given is a decider guarding whether or not the error should be
handled. The handler will always Right and no errors are Left'ed
through. If the decider returns Nothing, the error will be thrown
further up.

:: MonadError e m | |

=> m a | Monadic operation |

-> m b | Guard |

-> m a | Returns: A new monad. |

`finallyError`

is a monadic version of the classic UNWIND-PROTECT of
lisp fame. Given parameters m and after (both monads) we proceed to
work on m. If an error is caught, we execute the out-guard, after,
before rethrowing the error. If m does not fail, after is executed
and the value of m is returned.

:: MonadError e m | |

=> m a | Before (in-guard) monad |

-> (a -> m b) | After (out-guard) operation. Fed output of before |

-> (a -> m c) | Monad to work on. Fed with output of before |

-> m c | Resulting monad. |

`bracketError`

is the monadic version of DYNAMIC-WIND from Scheme
fame. Parameters are: before, after and m. before is the in-guard
being executed before m. after is the out-guard and protects fails
of the m.
In the Haskell world, this scheme is called a bracket and is often
seen employed to manage resources.

:: MonadError e m | |

=> m a | Before (in-guard) |

-> m b | After (out-guard) |

-> m c | Monad to work on |

-> m c | Resulting monad |

`bracketError_`

is the non-bound version of `bracketError`

. The
naming scheme follows usual Haskell convention.