hexpr-0.0.0.0: A framework for symbolic, homoiconic languages.

Safe HaskellSafe-Inferred

Control.Monad.Errors

Contents

Description

In many error-checking algorithms, it is desireable to report several errors rather than simply terminate on detecting the first error.

Where Either and Error terminates on the first error, Errors can recover at specified points and continue error-checking. Even after a recovery, the prior errors are logged. If any errors occured during error-checking, this si an error in the whole computation.

Synopsis

Errors Monad

type Errors e = ErrorsT e IdentitySource

Shortcut for ErrorsT over the Identity monad.

runErrors :: Monoid e => Errors e a -> Either e aSource

Perform an error-reporting computation.

Error Reporting Functions

err :: (Monad m, Monoid e) => e -> ErrorsT e m aSource

Report an error.

err1 :: Monad m => e -> ErrorsT [e] m aSource

Report one error accumulating in a list.

choice :: (Monad m, Monoid e) => e -> [ErrorsT e m a] -> ErrorsT e m aSource

Try several alternatives (in order), but if none succeed, raise the passed error.

recover :: (Monad m, Monoid e) => a -> ErrorsT e m a -> ErrorsT e m aSource

If the action returns an error, relpace the result with a default. The error is still logged and reported at the end of the computation.

recover_ :: (Monad m, Monoid e) => ErrorsT e m a -> ErrorsT e m ()Source

As recover, but any successful result value does not matter.

mapRecover :: (Monad m, Monoid e) => [ErrorsT e m a] -> ErrorsT e m [Maybe a]Source

Perform many error checks, recovering between each. The value at each index of the output list corresponds to the index of the input computation list. Error values are Nothing in the output, successful values are wrapped in Just.

unrecover :: (Monad m, Monoid e) => ErrorsT e m ()Source

If any errors have been detected, cuase them to be loud again.

Hoisting Functions

hoistMaybe :: (Monad m, Monoid e) => e -> Maybe a -> ErrorsT e m aSource

Turn a Maybe computation into an ErrorsT computation.

hoistEither :: (Monad m, Monoid e) => Either e a -> ErrorsT e m aSource

Turn an Either computation into an ErrorsT computation.

hoistEither1 :: Monad m => Either e a -> ErrorsT [e] m aSource

Turn an Either computation into an ErrorsT computation when accumulating a list.

Errors Transformer

data ErrorsT e m a Source

Computations that can collect multiple errors.

Instances

Monoid e => MonadTrans (ErrorsT e) 
(Monad m, Monoid e) => Monad (ErrorsT e m) 
(Monad m, Monoid e) => Functor (ErrorsT e m) 
(Monad m, Monoid e) => Applicative (ErrorsT e m) 
(MonadIO m, Monoid e) => MonadIO (ErrorsT e m) 

runErrorsT :: (Monad m, Monoid e) => ErrorsT e m a -> m (Either e a)Source

Perform the error reporting part of a computation.