attempt-0.0.0: Error handling using extensible exceptions outside the IO monad.Source codeContentsIndex
Data.Attempt
Description
A universal data type for computations which may fail. Errors are reported using extensible exceptions. These exceptions are not explicitly stated; if you want this kind of functionality, something like control-monad-exception might be a more appropriate fit.
Synopsis
data Attempt v
= Success v
| forall e . Exception e => Failure e
class FromAttempt a where
fromAttempt :: Attempt v -> a v
fa :: FromAttempt a => Attempt v -> a v
attempt :: (forall e. Exception e => e -> b) -> (a -> b) -> Attempt a -> b
makeHandler :: [AttemptHandler v] -> v -> forall e. Exception e => e -> v
data AttemptHandler v
module Control.Monad.Attempt.Class
Documentation
data Attempt v Source
Contains either a Success value or a Failure exception.
Constructors
Success v
forall e . Exception e => Failure e
show/hide Instances
class FromAttempt a whereSource

Any type which can be converted from an Attempt. The included instances are your "usual suspects" for dealing with error handling. They include:

IO: For the IO instance, any exceptions in the Attempt are thrown as runtime exceptions.

Maybe: Returns Nothing on Failure, or Just on Success.

List: Returns the empty list on Failure, or a singleton list on Success.

Either String: Returns Left (show exception) on Failure, or Right on Success.

Either Exception: Returns Left exception on Failure, or Right on Success.

Methods
fromAttempt :: Attempt v -> a vSource
show/hide Instances
fa :: FromAttempt a => Attempt v -> a vSource
A shortcut for fromAttempt.
attemptSource
::
=> forall e. Exception e => e -> bsuccess handler
-> a -> b
-> Attempt a
-> b

Process either the exception or value in an Attempt to produce a result.

This function is modeled after maybe and either. The first argument must accept any instances of Exception. If you want to handle multiple types of exceptions, see makeHandler. The second argument converts the success value.

makeHandler :: [AttemptHandler v] -> v -> forall e. Exception e => e -> vSource

Convert multiple AttemptHandlers and a default value into an exception handler.

This is a convenience function when you want to have special handling for a few types of Exceptions and provide another value for anything else.

data AttemptHandler v Source
A simple wrapper value necesary due to the Haskell type system. Wraps a function from a *specific* Exception type to some value.
module Control.Monad.Attempt.Class
Produced by Haddock version 2.6.0