-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simplified error-handling -- -- The one-stop shop for all your error-handling needs! Just import -- Control.Error. -- -- This library encourages an error-handling style that directly uses the -- type system, rather than out-of-band exceptions. @package errors @version 2.1.3 -- | This module provides throwEither and catchEither for -- Either. These two functions reside here because -- throwEither and catchEither correspond to return -- and (>>=) for the flipped Either monad: -- EitherR. Additionally, this module defines handleE as -- the flipped version of catchE for ExceptT. -- -- throwEither and catchEither improve upon -- MonadError because: -- --
-- runExceptRT $ do -- e2 <- ioExceptionHandler e1 -- bool <- arithmeticExceptionhandler e2 -- when bool $ lift $ putStrLn "DEBUG: Arithmetic handler did something" ---- -- If any of the above error handlers succeed, no other handlers -- are tried. -- -- If you choose not to typefully distinguish between the error and -- sucess monad, then use flipEither and flipET, which swap -- the type variables without changing the type. module Data.EitherR -- | If "Either e r" is the error monad, then "EitherR r -- e" is the corresponding success monad, where: -- --
-- bool a b c == if c then b else a --bool :: a -> a -> Bool -> a -- | An infix form of fromMaybe with arguments flipped. (?:) :: Maybe a -> a -> a -- | Case analysis for MaybeT -- -- Use the first argument if the MaybeT computation fails, -- otherwise apply the function to the successful result. maybeT :: Monad m => m b -> (a -> m b) -> MaybeT m a -> m b -- | Analogous to Just and equivalent to return just :: (Monad m) => a -> MaybeT m a -- | Analogous to Nothing and equivalent to mzero nothing :: (Monad m) => MaybeT m a -- | Analogous to isJust, but for MaybeT isJustT :: (Monad m) => MaybeT m a -> m Bool -- | Analogous to isNothing, but for MaybeT isNothingT :: (Monad m) => MaybeT m a -> m Bool -- | Returns whether argument is a Left isLeft :: Either a b -> Bool -- | Returns whether argument is a Right isRight :: Either a b -> Bool -- | fmap specialized to Either, given a name symmetric to -- fmapL fmapR :: (a -> b) -> Either l a -> Either l b -- | Run multiple Either computations and succeed if all of them -- succeed -- -- mappends all successes or failures newtype AllE e r AllE :: Either e r -> AllE e r [runAllE] :: AllE e r -> Either e r -- | Run multiple Either computations and succeed if any of them -- succeed -- -- mappends all successes or failures newtype AnyE e r AnyE :: Either e r -> AnyE e r [runAnyE] :: AnyE e r -> Either e r -- | Analogous to isLeft, but for ExceptT isLeftT :: (Monad m) => ExceptT a m b -> m Bool -- | Analogous to isRight, but for ExceptT isRightT :: (Monad m) => ExceptT a m b -> m Bool -- | fmap specialized to ExceptT, given a name symmetric to -- fmapLT fmapRT :: (Monad m) => (a -> b) -> ExceptT l m a -> ExceptT l m b -- | Fold an ExceptT by providing one continuation for each -- constructor exceptT :: Monad m => (a -> m c) -> (b -> m c) -> ExceptT a m b -> m c -- | Transform the left and right value bimapExceptT :: Functor m => (e -> f) -> (a -> b) -> ExceptT e m a -> ExceptT f m b -- | Write a string to standard error err :: String -> IO () -- | Write a string with a newline to standard error errLn :: String -> IO () -- | Catch IOExceptions and convert them to the ExceptT monad tryIO :: MonadIO m => IO a -> ExceptT IOException m a -- | Catch all exceptions, except for asynchronous exceptions found in -- base and convert them to the ExceptT monad syncIO :: Unexceptional m => IO a -> ExceptT SomeException m a instance (GHC.Base.Monoid e, GHC.Base.Monoid r) => GHC.Base.Monoid (Control.Error.Util.AllE e r) instance (GHC.Base.Monoid e, GHC.Base.Monoid r) => GHC.Base.Monoid (Control.Error.Util.AnyE e r) -- | Use this module if you like to write simple scripts with -- String-based errors, but you prefer to use ExceptT to -- handle errors rather than Control.Exception. -- --
-- import Control.Error -- -- main = runScript $ do -- str <- scriptIO getLine -- n <- tryRead "Read failed" str -- scriptIO $ print (n + 1) --module Control.Error.Script -- | An IO action that can fail with a String error message type Script = ExceptT String IO -- | Runs the Script monad -- -- Prints the first error to stderr and exits with -- exitFailure runScript :: Script a -> IO a -- | scriptIO resembles lift, except it catches all -- exceptions and converts them to Strings. -- -- Note that scriptIO is compatible with the Script monad. scriptIO :: (MonadIO m) => IO a -> ExceptT String m a -- | This module extends the safe library's functions with -- corresponding versions compatible with Either and -- ExceptT, and also provides a few Maybe-compatible -- functions missing from safe. -- -- I suffix the Either-compatible functions with Err and -- prefix the ExceptT-compatible functions with try. -- -- Note that this library re-exports the Maybe compatible -- functions from safe in the Control.Error module, so -- they are not provided here. -- -- The 'Z'-suffixed functions generalize the Maybe -- functions to also work with anything that implements MonadPlus, -- including: -- -- module Control.Error.Safe -- | An assertion that fails in the Maybe monad assertMay :: Bool -> Maybe () -- | A fromRight that fails in the Maybe monad rightMay :: Either e a -> Maybe a -- | A tail that fails in the Either monad tailErr :: e -> [a] -> Either e [a] -- | An init that fails in the Either monad initErr :: e -> [a] -> Either e [a] -- | A head that fails in the Either monad headErr :: e -> [a] -> Either e a -- | A last that fails in the Either monad lastErr :: e -> [a] -> Either e a -- | A minimum that fails in the Either monad minimumErr :: (Ord a) => e -> [a] -> Either e a -- | A maximum that fails in the Either monad maximumErr :: (Ord a) => e -> [a] -> Either e a -- | A foldr1 that fails in the Either monad foldr1Err :: e -> (a -> a -> a) -> [a] -> Either e a -- | A foldl1 that fails in the Either monad foldl1Err :: e -> (a -> a -> a) -> [a] -> Either e a -- | A foldl1' that fails in the Either monad foldl1Err' :: e -> (a -> a -> a) -> [a] -> Either e a -- | A (!!) that fails in the Either monad atErr :: e -> [a] -> Int -> Either e a -- | A read that fails in the Either monad readErr :: (Read a) => e -> String -> Either e a -- | An assertion that fails in the Either monad assertErr :: e -> Bool -> Either e () -- | A fromJust that fails in the Either monad justErr :: e -> Maybe a -> Either e a -- | A tail that fails in the ExceptT monad tryTail :: (Monad m) => e -> [a] -> ExceptT e m [a] -- | An init that fails in the ExceptT monad tryInit :: (Monad m) => e -> [a] -> ExceptT e m [a] -- | A head that fails in the ExceptT monad tryHead :: (Monad m) => e -> [a] -> ExceptT e m a -- | A last that fails in the ExceptT monad tryLast :: (Monad m) => e -> [a] -> ExceptT e m a -- | A minimum that fails in the ExceptT monad tryMinimum :: (Monad m, Ord a) => e -> [a] -> ExceptT e m a -- | A maximum that fails in the ExceptT monad tryMaximum :: (Monad m, Ord a) => e -> [a] -> ExceptT e m a -- | A foldr1 that fails in the ExceptT monad tryFoldr1 :: (Monad m) => e -> (a -> a -> a) -> [a] -> ExceptT e m a -- | A foldl1 that fails in the ExceptT monad tryFoldl1 :: (Monad m) => e -> (a -> a -> a) -> [a] -> ExceptT e m a -- | A foldl1' that fails in the ExceptT monad tryFoldl1' :: (Monad m) => e -> (a -> a -> a) -> [a] -> ExceptT e m a -- | A (!!) that fails in the ExceptT monad tryAt :: (Monad m) => e -> [a] -> Int -> ExceptT e m a -- | A read that fails in the ExceptT monad tryRead :: (Monad m, Read a) => e -> String -> ExceptT e m a -- | An assertion that fails in the ExceptT monad tryAssert :: (Monad m) => e -> Bool -> ExceptT e m () -- | A fromJust that fails in the ExceptT monad tryJust :: (Monad m) => e -> Maybe a -> ExceptT e m a -- | A fromRight that fails in the ExceptT monad tryRight :: (Monad m) => Either e a -> ExceptT e m a -- | A tail that fails using mzero tailZ :: (MonadPlus m) => [a] -> m [a] -- | An init that fails using mzero initZ :: (MonadPlus m) => [a] -> m [a] -- | A head that fails using mzero headZ :: (MonadPlus m) => [a] -> m a -- | A last that fails using mzero lastZ :: (MonadPlus m) => [a] -> m a -- | A minimum that fails using mzero minimumZ :: (MonadPlus m) => (Ord a) => [a] -> m a -- | A maximum that fails using mzero maximumZ :: (MonadPlus m) => (Ord a) => [a] -> m a -- | A foldr1 that fails using mzero foldr1Z :: (MonadPlus m) => (a -> a -> a) -> [a] -> m a -- | A foldl1 that fails using mzero foldl1Z :: (MonadPlus m) => (a -> a -> a) -> [a] -> m a -- | A foldl1' that fails using mzero foldl1Z' :: (MonadPlus m) => (a -> a -> a) -> [a] -> m a -- | A (!!) that fails using mzero atZ :: (MonadPlus m) => [a] -> Int -> m a -- | A read that fails using mzero readZ :: (MonadPlus m) => (Read a) => String -> m a -- | An assertion that fails using mzero assertZ :: (MonadPlus m) => Bool -> m () -- | A fromJust that fails using mzero justZ :: (MonadPlus m) => Maybe a -> m a -- | A fromRight that fails using mzero rightZ :: (MonadPlus m) => Either e a -> m a -- | Import this module in your code to access the entire library's -- functionality: -- --
-- import Control.Error ---- -- This module exports the entire library as well as useful exports from -- other standard error-handling libraries: -- --