-- 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 1.1.1 -- | This modules provides newtypes which flip the type variables of -- Either and EitherT to access the symmetric monad over -- the opposite type variable. -- -- This module provides the following simple benefits to the casual user: -- --
-- runEitherRT $ 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. 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 -- | throwE in the error monad corresponds to return in the -- success monad throwE :: e -> Either e r -- | catchE in the error monad corresponds to (>>=) in -- the success monad catchE :: Either a r -> (a -> Either b r) -> Either b r -- | catchE with the arguments flipped handleE :: (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 -- | EitherR converted into a monad transformer newtype EitherRT r m e EitherRT :: EitherT e m r -> EitherRT r m e runEitherRT :: EitherRT r m e -> EitherT e m r -- | The dual to left and synonymous with succeedT right :: Monad m => r -> EitherRT r m e -- | Complete error handling, returning a result succeedT :: Monad m => r -> EitherRT r m e -- | Synonym for throwT left :: Monad m => e -> EitherT e m r -- | throwT in the error monad corresponds to return in the -- success monad throwT :: Monad m => e -> EitherT e m r -- | catchT in the error monad corresponds to (>>=) in -- the success monad catchT :: Monad m => EitherT a m r -> (a -> EitherT b m r) -> EitherT b m r -- | catchT with the arguments flipped handleT :: Monad m => (a -> EitherT b m r) -> EitherT a m r -> EitherT b m r -- | Map a function over the Left value of an EitherT fmapLT :: Monad m => (a -> b) -> EitherT a m r -> EitherT b m r instance MonadTrans (EitherRT r) instance Monad m => Monad (EitherRT r m) instance Monad m => Applicative (EitherRT r m) instance Monad m => Functor (EitherRT r m) instance Monad (EitherR r) instance Applicative (EitherR r) instance Functor (EitherR r) -- | Use this module to convert between Maybe, Either, -- MaybeT, and EitherT. module Control.Error.Util -- | Suppress the Left value of an Either hush :: Either a b -> Maybe b -- | Suppress the Left value of an EitherT hushT :: Monad m => EitherT 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 -> EitherT a m b -- | Lift a Maybe to the MaybeT monad liftMaybe :: Monad m => Maybe b -> MaybeT m b -- | Lift an Either to the EitherT monad liftEither :: Monad m => Either a b -> EitherT a m b -- | This module extends the safe library's functions with -- corresponding versions compatible with Either and -- EitherT. -- -- All functions take an exceptional value to return should they fail. -- -- I suffix the Either-compatible functions with Err and -- prefix the EitherT-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. module Control.Error.Safe -- | 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 -> a -> Either e a -- | A tail that fails in the EitherT monad tryTail :: Monad m => e -> [a] -> EitherT e m [a] -- | An init that fails in the EitherT monad tryInit :: Monad m => e -> [a] -> EitherT e m [a] -- | A head that fails in the EitherT monad tryHead :: Monad m => e -> [a] -> EitherT e m a -- | A last that fails in the EitherT monad tryLast :: Monad m => e -> [a] -> EitherT e m a -- | A minimum that fails in the EitherT monad tryMinimum :: (Monad m, Ord a) => e -> [a] -> EitherT e m a -- | A maximum that fails in the EitherT monad tryMaximum :: (Monad m, Ord a) => e -> [a] -> EitherT e m a -- | A foldr1 that fails in the EitherT monad tryFoldr1 :: Monad m => e -> (a -> a -> a) -> [a] -> EitherT e m a -- | A foldl1 that fails in the EitherT monad tryFoldl1 :: Monad m => e -> (a -> a -> a) -> [a] -> EitherT e m a -- | A foldl1' that fails in the EitherT monad tryFoldl1' :: Monad m => e -> (a -> a -> a) -> [a] -> EitherT e m a -- | A (!!) that fails in the EitherT monad tryAt :: Monad m => e -> [a] -> Int -> EitherT e m a -- | A read that fails in the EitherT monad tryRead :: (Monad m, Read a) => e -> String -> EitherT e m a -- | An assertion that fails in the EitherT monad tryAssert :: Monad m => e -> Bool -> a -> EitherT e m a -- | Use this module if you like to write simple scripts, but you prefer to -- use EitherT to handle errors rather than -- Control.Exception. -- --
-- import Control.Error -- -- main = runScript $ do -- str <- tryIO getLine -- n <- tryRead "Read failed" str -- tryIO $ print (n + 1) --module Control.Error.Script -- | An IO action that can fail with a String error message type Script = EitherT String IO -- | Runs the Script monad -- -- Prints the first error to stderr and exits with -- exitFailure runScript :: Script a -> IO a -- | A Maybe that fails in the Script monad tryMaybe :: String -> Maybe a -> Script a -- | An Either that fails in the Script monad tryEither :: Either String r -> Script r -- | tryIO is like lift, except it converts exceptions to -- the Script monad tryIO :: IO a -> Script 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