-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simplified error-handling -- @package errors @version 2.0.1 -- | 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: -- -- newtype EitherR r e EitherR :: Either e r -> EitherR r e runEitherR :: EitherR r e -> Either e r -- | Complete error handling, returning a result succeed :: r -> EitherR r e -- | throwEither in the error monad corresponds to return in -- the success monad throwEither :: e -> Either e r -- | catchEither in the error monad corresponds to -- (>>=) in the success monad catchEither :: Either a r -> (a -> Either b r) -> Either b r -- | catchEither with the arguments flipped handleEither :: (a -> Either b r) -> Either a r -> Either b r -- | Map a function over the Left value of an Either fmapL :: (a -> b) -> Either a r -> Either b r -- | Flip the type variables of Either flipEither :: Either a b -> Either b a -- | EitherR converted into a monad transformer newtype ExceptRT r m e ExceptRT :: ExceptT e m r -> ExceptRT r m e runExceptRT :: ExceptRT r m e -> ExceptT e m r -- | Complete error handling, returning a result succeedT :: Monad m => r -> ExceptRT r m e -- | catchT with the arguments flipped handleE :: Monad m => (a -> ExceptT b m r) -> ExceptT a m r -> ExceptT b m r -- | Map a function over the Left value of an ExceptT fmapLT :: Monad m => (a -> b) -> ExceptT a m r -> ExceptT b m r -- | Flip the type variables of an ExceptT flipET :: Monad m => ExceptT a m b -> ExceptT b m a instance MonadIO m => MonadIO (ExceptRT r m) instance MonadTrans (ExceptRT r) instance (Monad m, Monoid r) => MonadPlus (ExceptRT r m) instance (Monad m, Monoid r) => Alternative (ExceptRT r m) instance Monad m => Monad (ExceptRT r m) instance Monad m => Applicative (ExceptRT r m) instance Monad m => Functor (ExceptRT r m) instance Monoid r => MonadPlus (EitherR r) instance Monoid r => Alternative (EitherR r) instance Monad (EitherR r) instance Applicative (EitherR r) instance Functor (EitherR r) -- | This module exports miscellaneous error-handling functions. module Control.Error.Util -- | Suppress the Left value of an Either hush :: Either a b -> Maybe b -- | Suppress the Left value of an ExceptT hushT :: Monad m => ExceptT a m b -> MaybeT m b -- | Tag the Nothing value of a Maybe note :: a -> Maybe b -> Either a b -- | Tag the Nothing value of a MaybeT noteT :: Monad m => a -> MaybeT m b -> ExceptT a m b -- | Lift a Maybe to the MaybeT monad hoistMaybe :: Monad m => Maybe b -> MaybeT m b -- | Upgrade an Either to an ExceptT hoistEither :: Monad m => Either e a -> ExceptT e m a -- | Convert a Maybe value into the ExceptT monad (??) :: Applicative m => Maybe a -> e -> ExceptT e m a -- | Convert an applicative Maybe value into the ExceptT -- monad (!?) :: Applicative m => m (Maybe a) -> e -> ExceptT e m a -- | Convert a Maybe value into the ExceptT monad -- -- Named version of (??) with arguments flipped failWith :: Applicative m => e -> Maybe a -> ExceptT e m a -- | Convert an applicative Maybe value into the ExceptT -- monad -- -- Named version of (!?) with arguments flipped failWithM :: Applicative m => e -> m (Maybe a) -> ExceptT e m a -- | Case analysis for the Bool type. -- --
--   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 :: MonadIO m => IO a -> ExceptT SomeException m a instance (Monoid e, Monoid r) => Monoid (AnyE e r) instance (Monoid e, Monoid r) => Monoid (AllE 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: -- -- module Control.Error