-- 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.4.2 -- | This module provides throwE and catchE for -- Either. These two functions reside here because throwE -- and catchE correspond to return and (>>=) -- for the flipped Either monad: EitherR. Similarly, this -- module defines throwT and catchT for EitherT, -- which correspond to the Monad operations for EitherRT. -- -- These throw and catch functions improve upon MonadError -- because: -- -- -- -- More advanced users can use EitherR and EitherRT to -- program in an entirely symmetric "success monad" where exceptional -- results are the norm and successful results terminate the computation. -- This allows you to chain error-handlers using do notation and -- pass around exceptional values of varying types until you can finally -- recover from the error: -- --
--   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. -- -- If you choose not to typefully distinguish between the error and -- sucess monad, then use flipE 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 -- | 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 -- | Flip the type variables of Either flipE :: Either a b -> Either b a -- | 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 -- | Complete error handling, returning a result succeedT :: Monad m => r -> EitherRT r m e -- | 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 -- | Flip the type variables of an EitherT flipET :: Monad m => EitherT a m b -> EitherT b m a instance MonadIO m => MonadIO (EitherRT r m) instance MonadTrans (EitherRT r) instance (Monad m, Monoid r) => MonadPlus (EitherRT r m) instance (Monad m, Monoid r) => Alternative (EitherRT r m) instance Monad m => Monad (EitherRT r m) instance Monad m => Applicative (EitherRT r m) instance Monad m => Functor (EitherRT 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 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 hoistMaybe :: Monad m => Maybe b -> MaybeT m b -- | Convert a Maybe value into the EitherT monad (??) :: Applicative m => Maybe a -> e -> EitherT e m a -- | Convert an applicative Maybe value into the EitherT -- monad (!?) :: Applicative m => m (Maybe a) -> e -> EitherT e m 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 -- | 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 -- | fmap specialized to EitherT, given a name symmetric to -- fmapLT fmapRT :: Monad m => (a -> b) -> EitherT l m a -> EitherT l 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 EitherT monad tryIO :: MonadIO m => IO a -> EitherT IOException m a -- | Catch all exceptions, except for asynchronous exceptions found in -- base and convert them to the EitherT monad syncIO :: MonadIO m => IO a -> EitherT SomeException m a -- | Use this module if you like to write simple scripts with -- String-based errors, but you prefer to use EitherT 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 = EitherT 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 -> EitherT String m a -- | This module extends the safe library's functions with -- corresponding versions compatible with Either and -- EitherT, and also provides a few Maybe-compatible -- functions missing from safe. -- -- 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. -- -- 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 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 -> EitherT e m () -- | A fromJust that fails in the EitherT monad tryJust :: Monad m => e -> Maybe a -> EitherT e m a -- | A fromRight that fails in the EitherT monad tryRight :: Monad m => Either e a -> EitherT 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: -- -- -- -- This module does not re-export partial functions from other libraries. module Control.Error