Control.Error.Util

errors-2.1.2: Simplified error-handling

Safe Haskell | Safe
Language | Haskell98

Control.Error.Util

Contents

- Conversion
- Bool
- Maybe
- MaybeT
- Either
- ExceptT
- Error Reporting
- Exceptions

Description

This module exports miscellaneous error-handling functions.

Synopsis

- hush :: Either a b -> Maybe b
- hushT :: Monad m => ExceptT a m b -> MaybeT m b
- note :: a -> Maybe b -> Either a b
- noteT :: Monad m => a -> MaybeT m b -> ExceptT a m b
- hoistMaybe :: Monad m => Maybe b -> MaybeT m b
- hoistEither :: Monad m => Either e a -> ExceptT e m a
- (??) :: Applicative m => Maybe a -> e -> ExceptT e m a
- (!?) :: Applicative m => m (Maybe a) -> e -> ExceptT e m a
- failWith :: Applicative m => e -> Maybe a -> ExceptT e m a
- failWithM :: Applicative m => e -> m (Maybe a) -> ExceptT e m a
- bool :: a -> a -> Bool -> a
- (?:) :: Maybe a -> a -> a
- maybeT :: Monad m => m b -> (a -> m b) -> MaybeT m a -> m b
- just :: Monad m => a -> MaybeT m a
- nothing :: Monad m => MaybeT m a
- isJustT :: Monad m => MaybeT m a -> m Bool
- isNothingT :: Monad m => MaybeT m a -> m Bool
- isLeft :: Either a b -> Bool
- isRight :: Either a b -> Bool
- fmapR :: (a -> b) -> Either l a -> Either l b
- newtype AllE e r = AllE {
  - runAllE :: Either e r
  }
- newtype AnyE e r = AnyE {
  - runAnyE :: Either e r
  }
- isLeftT :: Monad m => ExceptT a m b -> m Bool
- isRightT :: Monad m => ExceptT a m b -> m Bool
- fmapRT :: Monad m => (a -> b) -> ExceptT l m a -> ExceptT l m b
- exceptT :: Monad m => (a -> m c) -> (b -> m c) -> ExceptT a m b -> m c
- bimapExceptT :: Functor m => (e -> f) -> (a -> b) -> ExceptT e m a -> ExceptT f m b
- err :: String -> IO ()
- errLn :: String -> IO ()
- tryIO :: MonadIO m => IO a -> ExceptT IOException m a
- syncIO :: Unexceptional m => IO a -> ExceptT SomeException m a

# Conversion

Use these functions to convert between `Maybe`, `Either`, `MaybeT`, and `ExceptT`.

hush :: Either a b -> Maybe b

Suppress the `Left` value of an `Either`

hushT :: Monad m => ExceptT a m b -> MaybeT m b

Suppress the `Left` value of an `ExceptT`

note :: a -> Maybe b -> Either a b

Tag the `Nothing` value of a `Maybe`

noteT :: Monad m => a -> MaybeT m b -> ExceptT a m b

Tag the `Nothing` value of a `MaybeT`

hoistMaybe :: Monad m => Maybe b -> MaybeT m b

Lift a `Maybe` to the `MaybeT` monad

hoistEither :: Monad m => Either e a -> ExceptT e m a

Upgrade an `Either` to an `ExceptT`

(??) :: Applicative m => Maybe a -> e -> ExceptT e m a

Convert a `Maybe` value into the `ExceptT` monad

(!?) :: Applicative m => m (Maybe a) -> e -> ExceptT e m a

Convert an applicative `Maybe` value into the `ExceptT` monad

failWith :: Applicative m => e -> Maybe a -> ExceptT e m a

Convert a `Maybe` value into the `ExceptT` monad

Named version of (`??`) with arguments flipped

failWithM :: Applicative m => e -> m (Maybe a) -> ExceptT e m a

Convert an applicative `Maybe` value into the `ExceptT` monad

Named version of (`!?`) with arguments flipped

# Bool

bool :: a -> a -> Bool -> a

Case analysis for the `Bool` type.

    bool a b c == if c then b else a

# Maybe

(?:) :: Maybe a -> a -> a

An infix form of `fromMaybe` with arguments flipped.

# MaybeT

maybeT :: Monad m => m b -> (a -> m b) -> MaybeT m a -> m b

Case analysis for `MaybeT`

Use the first argument if the `MaybeT` computation fails, otherwise apply the function to the successful result.

just :: Monad m => a -> MaybeT m a

Analogous to `Just` and equivalent to `return`

nothing :: Monad m => MaybeT m a

Analogous to `Nothing` and equivalent to `mzero`

isJustT :: Monad m => MaybeT m a -> m Bool

Analogous to `isJust`, but for `MaybeT`

isNothingT :: Monad m => MaybeT m a -> m Bool

Analogous to `isNothing`, but for `MaybeT`

# Either

isLeft :: Either a b -> Bool

Returns whether argument is a `Left`

isRight :: Either a b -> Bool

Returns whether argument is a `Right`

fmapR :: (a -> b) -> Either l a -> Either l b

`fmap` specialized to `Either`, given a name symmetric to `fmapL`

newtype AllE e r

Run multiple `Either` computations and succeed if all of them succeed

`mappend`s all successes or failures

Constructors

AllE |
Fields runAllE :: Either e r

Instances

(Monoid e, Monoid r) => Monoid (AllE e r) |

newtype AnyE e r

Run multiple `Either` computations and succeed if any of them succeed

`mappend`s all successes or failures

Constructors

AnyE |
Fields runAnyE :: Either e r

Instances

(Monoid e, Monoid r) => Monoid (AnyE e r) |

# ExceptT

isLeftT :: Monad m => ExceptT a m b -> m Bool

Analogous to `isLeft`, but for `ExceptT`

isRightT :: Monad m => ExceptT a m b -> m Bool

Analogous to `isRight`, but for `ExceptT`

fmapRT :: Monad m => (a -> b) -> ExceptT l m a -> ExceptT l m b

`fmap` specialized to `ExceptT`, given a name symmetric to `fmapLT`

exceptT :: Monad m => (a -> m c) -> (b -> m c) -> ExceptT a m b -> m c

Fold an `ExceptT` by providing one continuation for each constructor

bimapExceptT :: Functor m => (e -> f) -> (a -> b) -> ExceptT e m a -> ExceptT f m b

Transform the left and right value

# Error Reporting

err :: String -> IO ()

Write a string to standard error

errLn :: String -> IO ()

Write a string with a newline to standard error

# Exceptions

tryIO :: MonadIO m => IO a -> ExceptT IOException m a

Catch `IOException`s and convert them to the `ExceptT` monad

syncIO :: Unexceptional m => IO a -> ExceptT SomeException m a

Catch all exceptions, except for asynchronous exceptions found in `base` and convert them to the `ExceptT` monad