arrows-0.4.4.2: Arrow classes and transformers

Copyright | (c) Ross Paterson 2003
License | BSD-style (see the LICENSE file in the distribution)
Maintainer | R.Paterson@city.ac.uk
Stability | experimental
Portability | non-portable (multi-parameter type classes)
Safe Haskell | Safe-Inferred
Language | Haskell98

Control.Arrow.Transformer.Error

Description

An arrow transformer that adds error handling.

TODO: the operations here are inconsistent with other arrow transformers.

Synopsis

- newtype ErrorArrow ex (a :: Type -> Type -> Type) b c = ErrorArrow (a b (Either ex c))
- runError :: ArrowChoice a => ErrorArrow ex a e b -> a (e, ex) b -> a e b
- class (ArrowError ex a, Arrow a') => ArrowAddError ex (a :: Type -> Type -> Type) (a' :: Type -> Type -> Type) | a -> a' where
  - liftError :: a' e b -> a e b
  - elimError :: a e b -> a' (e, ex) b -> a' e b

# Documentation

newtype ErrorArrow ex (a :: Type -> Type -> Type) b c Source #

An arrow that augments an existing arrow with possible errors. The `ArrowError` class contains methods for raising and handling these errors.

Constructors

ErrorArrow (a b (Either ex c)) |

#### Instances

Instances details

ArrowChoice a => ArrowError ex (ErrorArrow ex a) Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods raise :: ErrorArrow ex a ex b Source # handle :: ErrorArrow ex a e b -> ErrorArrow ex a (e, ex) b -> ErrorArrow ex a e b Source # tryInUnless :: ErrorArrow ex a e b -> ErrorArrow ex a (e, b) c -> ErrorArrow ex a (e, ex) c -> ErrorArrow ex a e c Source # newError :: ErrorArrow ex a e b -> ErrorArrow ex a e (Either ex b) Source #
(ArrowReader r a, ArrowChoice a) => ArrowReader r (ErrorArrow ex a) Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods readState :: ErrorArrow ex a b r Source # newReader :: ErrorArrow ex a e b -> ErrorArrow ex a (e, r) b Source #
(ArrowState s a, ArrowChoice a) => ArrowState s (ErrorArrow ex a) Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods fetch :: ErrorArrow ex a e s Source # store :: ErrorArrow ex a s () Source #
(ArrowWriter w a, ArrowChoice a) => ArrowWriter w (ErrorArrow ex a) Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods write :: ErrorArrow ex a w () Source # newWriter :: ErrorArrow ex a e b -> ErrorArrow ex a e (b, w) Source #
ArrowChoice a => Category (ErrorArrow ex a :: Type -> Type -> Type) Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods id :: ErrorArrow ex a a0 a0 Source # (.) :: ErrorArrow ex a b c -> ErrorArrow ex a a0 b -> ErrorArrow ex a a0 c Source #
ArrowChoice a => ArrowAddError ex (ErrorArrow ex a) a Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods liftError :: a e b -> ErrorArrow ex a e b Source # elimError :: ErrorArrow ex a e b -> a (e, ex) b -> a e b Source #
(ArrowAddReader r a a', ArrowChoice a, ArrowChoice a') => ArrowAddReader r (ErrorArrow ex a) (ErrorArrow ex a') Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods liftReader :: ErrorArrow ex a' e b -> ErrorArrow ex a e b Source # elimReader :: ErrorArrow ex a e b -> ErrorArrow ex a' (e, r) b Source #
(ArrowAddState s a a', ArrowChoice a, ArrowChoice a') => ArrowAddState s (ErrorArrow ex a) (ErrorArrow ex a') Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods liftState :: ErrorArrow ex a' e b -> ErrorArrow ex a e b Source # elimState :: ErrorArrow ex a e b -> ErrorArrow ex a' (e, s) (b, s) Source #
(ArrowAddWriter w a a', ArrowChoice a, ArrowChoice a') => ArrowAddWriter w (ErrorArrow ex a) (ErrorArrow ex a') Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods liftWriter :: ErrorArrow ex a' e b -> ErrorArrow ex a e b Source # elimWriter :: ErrorArrow ex a e b -> ErrorArrow ex a' e (b, w) Source #
ArrowChoice a => ArrowTransformer (ErrorArrow ex) a Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods lift :: a b c -> ErrorArrow ex a b c Source #
ArrowChoice a => Arrow (ErrorArrow ex a) Source # |

Instance details

Defined in Control.Arrow.Transformer.Error

Methods

arr :: (b -> c) -> ErrorArrow ex a b c Source #

first :: ErrorArrow ex a b c -> ErrorArrow ex a (b, d) (c, d) Source #

second :: ErrorArrow ex a b c -> ErrorArrow ex a (d, b) (d, c) Source #

(***) :: ErrorArrow ex a b c -> ErrorArrow ex a b' c' -> ErrorArrow ex a (b, b') (c, c') Source #

(&&&) :: ErrorArrow ex a b c -> ErrorArrow ex a b c' -> ErrorArrow ex a b (c, c') Source #

(ArrowChoice a, ArrowApply a) => ArrowApply (ErrorArrow ex a) Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods app :: ErrorArrow ex a (ErrorArrow ex a b c, b) c Source #
ArrowChoice a => ArrowChoice (ErrorArrow ex a) Source # |

Instance details

Defined in Control.Arrow.Transformer.Error

Methods

left :: ErrorArrow ex a b c -> ErrorArrow ex a (Either b d) (Either c d) Source #

right :: ErrorArrow ex a b c -> ErrorArrow ex a (Either d b) (Either d c) Source #

(+++) :: ErrorArrow ex a b c -> ErrorArrow ex a b' c' -> ErrorArrow ex a (Either b b') (Either c c') Source #

(|||) :: ErrorArrow ex a b d -> ErrorArrow ex a c d -> ErrorArrow ex a (Either b c) d Source #

(ArrowChoice a, ArrowLoop a) => ArrowLoop (ErrorArrow ex a) Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods loop :: ErrorArrow ex a (b, d) (c, d) -> ErrorArrow ex a b c Source #
(Monoid ex, ArrowChoice a) => ArrowPlus (ErrorArrow ex a) Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods (<+>) :: ErrorArrow ex a b c -> ErrorArrow ex a b c -> ErrorArrow ex a b c Source #
(Monoid ex, ArrowChoice a) => ArrowZero (ErrorArrow ex a) Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods zeroArrow :: ErrorArrow ex a b c Source #
(Monoid ex, ArrowChoice a) => Alternative (ErrorArrow ex a b) Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods empty :: ErrorArrow ex a b a0 Source # (<|>) :: ErrorArrow ex a b a0 -> ErrorArrow ex a b a0 -> ErrorArrow ex a b a0 Source # some :: ErrorArrow ex a b a0 -> ErrorArrow ex a b [a0] Source # many :: ErrorArrow ex a b a0 -> ErrorArrow ex a b [a0] Source #
ArrowChoice a => Applicative (ErrorArrow ex a b) Source # |

Instance details

Defined in Control.Arrow.Transformer.Error

Methods

pure :: a0 -> ErrorArrow ex a b a0 Source #

(<*>) :: ErrorArrow ex a b (a0 -> b0) -> ErrorArrow ex a b a0 -> ErrorArrow ex a b b0 Source #

liftA2 :: (a0 -> b0 -> c) -> ErrorArrow ex a b a0 -> ErrorArrow ex a b b0 -> ErrorArrow ex a b c Source #

(*>) :: ErrorArrow ex a b a0 -> ErrorArrow ex a b b0 -> ErrorArrow ex a b b0 Source #

(<*) :: ErrorArrow ex a b a0 -> ErrorArrow ex a b b0 -> ErrorArrow ex a b a0 Source #

ArrowChoice a => Functor (ErrorArrow ex a b) Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods fmap :: (a0 -> b0) -> ErrorArrow ex a b a0 -> ErrorArrow ex a b b0 Source # (<$) :: a0 -> ErrorArrow ex a b b0 -> ErrorArrow ex a b a0 Source #
(Monoid ex, ArrowChoice a) => Monoid (ErrorArrow ex a b c) Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods mempty :: ErrorArrow ex a b c Source # mappend :: ErrorArrow ex a b c -> ErrorArrow ex a b c -> ErrorArrow ex a b c Source # mconcat :: [ErrorArrow ex a b c] -> ErrorArrow ex a b c Source #
(Monoid ex, ArrowChoice a) => Semigroup (ErrorArrow ex a b c) Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods (<>) :: ErrorArrow ex a b c -> ErrorArrow ex a b c -> ErrorArrow ex a b c Source # sconcat :: NonEmpty (ErrorArrow ex a b c) -> ErrorArrow ex a b c Source # stimes :: Integral b0 => b0 -> ErrorArrow ex a b c -> ErrorArrow ex a b c Source #

runError Source #

Arguments

:: ArrowChoice a |
=> ErrorArrow ex a e b | computation that may raise errors
-> a (e, ex) b | computation to handle errors
-> a e b |

Encapsulate an error-raising computation, by completely handling any errors.

Typical usage in arrow notation:

       proc p -> ...
           body `runError` \ex -> handler

class (ArrowError ex a, Arrow a') => ArrowAddError ex (a :: Type -> Type -> Type) (a' :: Type -> Type -> Type) | a -> a' where Source #

Adding a `ErrorArrow` to an arrow type, but not necessarily as the outer arrow transformer.

Typically a composite arrow type is built by applying a series of arrow transformer to a base arrow (usually either a function arrow or a `Kleisli` arrow. One can add a transformer to the top of this stack using the `lift` method of the `ArrowTransformer` class, or remove a state transformer from the top of the stack using the `runError` encapsulation operator. The methods of this class add and remove state transformers anywhere in the stack. In the instance

       instance Arrow a => ArrowAddError ex (ArrowError ex a) a

they are equivalent to `lift` and `runError` respectively. Instances are lifted through other transformers with

       instance ArrowAddError ex a a' =>
           ArrowAddError ex (FooArrow a) (FooArrow a')

This could be combined with `handle`, since the resulting arrow is always the arrow of the handler. Separating them has the advantage of consistency with the other arrows, and might give more helpful type error messages.

Methods

liftError :: a' e b -> a e b Source #

Lift a computation from an arrow to one with error handling.

Typical usage in arrow notation:

       proc p -> ...
           (|liftError cmd|)

elimError :: a e b -> a' (e, ex) b -> a' e b Source #

Elimination of errors from a computation, by completely handling any errors.

Typical usage in arrow notation:

       proc p -> ...
           body `elimError` \ex -> handler

#### Instances

Instances details

ArrowChoice a => ArrowAddError ex (ErrorArrow ex a) a Source # |
Instance details Defined in Control.Arrow.Transformer.Error Methods liftError :: a e b -> ErrorArrow ex a e b Source # elimError :: ErrorArrow ex a e b -> a (e, ex) b -> a e b Source #
ArrowAddError ex a a' => ArrowAddError ex (ReaderArrow r a) (ReaderArrow r a') Source # |
Instance details Defined in Control.Arrow.Transformer.Reader Methods liftError :: ReaderArrow r a' e b -> ReaderArrow r a e b Source # elimError :: ReaderArrow r a e b -> ReaderArrow r a' (e, ex) b -> ReaderArrow r a' e b Source #
ArrowAddError ex a a' => ArrowAddError ex (StateArrow s a) (StateArrow s a') Source # |
Instance details Defined in Control.Arrow.Transformer.State Methods liftError :: StateArrow s a' e b -> StateArrow s a e b Source # elimError :: StateArrow s a e b -> StateArrow s a' (e, ex) b -> StateArrow s a' e b Source #
(ArrowAddError ex a a', Applicative f) => ArrowAddError ex (StaticArrow f a) (StaticArrow f a') Source # |
Instance details Defined in Control.Arrow.Transformer.Static Methods liftError :: StaticArrow f a' e b -> StaticArrow f a e b Source # elimError :: StaticArrow f a e b -> StaticArrow f a' (e, ex) b -> StaticArrow f a' e b Source #
(ArrowAddError ex a a', Monoid w) => ArrowAddError ex (WriterArrow w a) (WriterArrow w a') Source # |
Instance details Defined in Control.Arrow.Transformer.Writer Methods liftError :: WriterArrow w a' e b -> WriterArrow w a e b Source # elimError :: WriterArrow w a e b -> WriterArrow w a' (e, ex) b -> WriterArrow w a' e b Source #