lambdabot-utils-4.2.1: Utility libraries for the advanced IRC bot, Lambdabot

Lambdabot.Error

Description

Error utilities

Synopsis

Documentation

catchErrorJustSource

Arguments

:: 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.

handleErrorSource

Arguments

:: MonadError e m 
=> (e -> m a)

Error handler

-> m a

Monad

-> m a

Resulting monad

handleError is the flipped version of catchError.

handleErrorJustSource

Arguments

:: 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.

tryErrorSource

Arguments

:: 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.

tryErrorJustSource

Arguments

:: 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.

finallyErrorSource

Arguments

:: 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.

bracketErrorSource

Arguments

:: 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.

bracketError_Source

Arguments

:: 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.