-- 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.0 -- | 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: -- --
-- 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 -- | 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 -- | 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: -- --
-- import Control.Error ---- -- This module exports the entire library as well as useful exports from -- other standard error-handling libraries: -- --