errors 1.4.1 → 1.4.2
raw patch · 6 files changed
+71/−22 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Control.Error.Util: (!?) :: Applicative m => m (Maybe a) -> e -> EitherT e m a
+ Control.Error.Util: (??) :: Applicative m => Maybe a -> e -> EitherT e m a
+ Control.Error.Util: syncIO :: MonadIO m => IO a -> EitherT SomeException m a
Files
- Control/Error.hs +2/−2
- Control/Error/Safe.hs +4/−2
- Control/Error/Script.hs +2/−4
- Control/Error/Util.hs +50/−6
- Data/EitherR.hs +8/−2
- errors.cabal +5/−6
Control/Error.hs view
@@ -1,5 +1,4 @@-{-|- Import this module in your code to access the entire library's+{-| Import this module in your code to access the entire library's functionality: > import Control.Error@@ -33,6 +32,7 @@ -} module Control.Error (+ -- * Re-exports module Control.Error.Safe, module Control.Error.Script, module Control.Error.Util,
Control/Error/Safe.hs view
@@ -1,5 +1,4 @@-{-|- This module extends the @safe@ library's functions with corresponding+{-| 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@. @@ -23,6 +22,7 @@ -- * Maybe-compatible functions assertMay, rightMay,+ -- * Either-compatible functions tailErr, initErr,@@ -37,6 +37,7 @@ readErr, assertErr, justErr,+ -- * EitherT-compatible functions tryTail, tryInit,@@ -52,6 +53,7 @@ tryAssert, tryJust, tryRight,+ -- * MonadPlus-compatible functions tailZ, initZ,
Control/Error/Script.hs view
@@ -33,8 +33,7 @@ -- | An 'IO' action that can fail with a 'String' error message type Script = EitherT String IO -{-|- Runs the 'Script' monad+{-| Runs the 'Script' monad Prints the first error to 'stderr' and exits with 'exitFailure' -}@@ -47,8 +46,7 @@ exitFailure Right a -> return a -{-|- 'scriptIO' resembles 'lift', except it catches all exceptions and converts+{-| 'scriptIO' resembles 'lift', except it catches all exceptions and converts them to 'String's. Note that 'scriptIO' is compatible with the 'Script' monad.
Control/Error/Util.hs view
@@ -8,28 +8,39 @@ note, noteT, hoistMaybe,+ (??),+ (!?),+ -- * MaybeT maybeT, just, nothing,+ -- * Either isLeft, isRight, fmapR,+ -- * EitherT fmapRT,+ -- * Error Reporting err, errLn,+ -- * Exceptions- tryIO+ tryIO,+ syncIO ) where -import Control.Exception (try, IOException)+import Control.Applicative (Applicative, pure, (<$>))+import qualified Control.Exception as Ex import Control.Monad (liftM) import Control.Monad.IO.Class (MonadIO(liftIO)) import Control.Monad.Trans.Either (EitherT(EitherT, runEitherT)) import Control.Monad.Trans.Maybe (MaybeT(MaybeT, runMaybeT))+import Data.Dynamic (Dynamic)+import System.Exit (ExitCode) import System.IO (hPutStr, hPutStrLn, stderr) -- For Documentation@@ -39,7 +50,7 @@ Use these functions to convert between 'Maybe', 'Either', 'MaybeT', and 'EitherT'. - Note that 'hoistEither' is provided by the @either@ package.+ Note that 'hoistEither' and 'eitherT' are provided by the @either@ package. -} -- | Suppress the 'Left' value of an 'Either' hush :: Either a b -> Maybe b@@ -61,6 +72,14 @@ hoistMaybe :: (Monad m) => Maybe b -> MaybeT m b hoistMaybe = MaybeT . return +-- | Convert a 'Maybe' value into the 'EitherT' monad+(??) :: Applicative m => Maybe a -> e -> EitherT e m a+(??) a e = EitherT (pure $ note e a)++-- | Convert an applicative 'Maybe' value into the 'EitherT' monad+(!?) :: Applicative m => m (Maybe a) -> e -> EitherT e m a+(!?) a e = EitherT (note e <$> a)+ {-| Case analysis for 'MaybeT' Use the first argument if the 'MaybeT' computation fails, otherwise apply@@ -101,6 +120,31 @@ errLn :: String -> IO () errLn = hPutStrLn stderr --- | Catch 'IOException's and convert them to the 'EitherT' monad-tryIO :: (MonadIO m) => IO a -> EitherT IOException m a-tryIO = EitherT . liftIO . try+-- | Catch 'Ex.IOException's and convert them to the 'EitherT' monad+tryIO :: (MonadIO m) => IO a -> EitherT Ex.IOException m a+tryIO = EitherT . liftIO . Ex.try++{-| Catch all exceptions, except for asynchronous exceptions found in @base@+ and convert them to the 'EitherT' monad+-}+syncIO :: MonadIO m => IO a -> EitherT Ex.SomeException m a+syncIO a = EitherT . liftIO $ Ex.catches (Right <$> a)+ [ Ex.Handler $ \e -> Ex.throw (e :: Ex.ArithException)+ , Ex.Handler $ \e -> Ex.throw (e :: Ex.ArrayException)+ , Ex.Handler $ \e -> Ex.throw (e :: Ex.AssertionFailed)+ , Ex.Handler $ \e -> Ex.throw (e :: Ex.AsyncException)+ , Ex.Handler $ \e -> Ex.throw (e :: Ex.BlockedIndefinitelyOnMVar)+ , Ex.Handler $ \e -> Ex.throw (e :: Ex.BlockedIndefinitelyOnSTM)+ , Ex.Handler $ \e -> Ex.throw (e :: Ex.Deadlock)+ , Ex.Handler $ \e -> Ex.throw (e :: Dynamic)+ , Ex.Handler $ \e -> Ex.throw (e :: Ex.ErrorCall)+ , Ex.Handler $ \e -> Ex.throw (e :: ExitCode)+ , Ex.Handler $ \e -> Ex.throw (e :: Ex.NestedAtomically)+ , Ex.Handler $ \e -> Ex.throw (e :: Ex.NoMethodError)+ , Ex.Handler $ \e -> Ex.throw (e :: Ex.NonTermination)+ , Ex.Handler $ \e -> Ex.throw (e :: Ex.PatternMatchFail)+ , Ex.Handler $ \e -> Ex.throw (e :: Ex.RecConError)+ , Ex.Handler $ \e -> Ex.throw (e :: Ex.RecSelError)+ , Ex.Handler $ \e -> Ex.throw (e :: Ex.RecUpdError)+ , Ex.Handler $ return . Left+ ]
Data/EitherR.hs view
@@ -1,5 +1,4 @@-{-|- This module provides 'throwE' and 'catchE' for 'Either'. These two+{-| 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@@ -32,24 +31,31 @@ module Data.EitherR ( -- * EitherR EitherR(..),+ -- ** Operations in the EitherR monad succeed,+ -- ** Conversions to the Either monad throwE, catchE, handleE, fmapL,+ -- ** Flip alternative flipE,+ -- * EitherRT EitherRT(..),+ -- ** Operations in the EitherRT monad succeedT,+ -- ** Conversions to the EitherT monad throwT, catchT, handleT, fmapLT,+ -- ** Flip alternative flipET, ) where
errors.cabal view
@@ -1,5 +1,5 @@ Name: errors-Version: 1.4.1+Version: 1.4.2 Cabal-Version: >=1.8.0.2 Build-Type: Simple License: BSD3@@ -16,17 +16,16 @@ This library encourages an error-handling style that directly uses the type system, rather than out-of-band exceptions. Category: Control, Error Handling-Tested-With: GHC ==7.4.1 Source-Repository head Type: git Location: https://github.com/Gabriel439/Haskell-Errors-Library Library Build-Depends:- base >= 4 && < 5,- either >= 3.1 && < 3.5,- safe >= 0.3.3 && < 0.4,- transformers >= 0.2 && < 0.4+ base >= 4 && < 5 ,+ either >= 3.1 && < 3.5,+ safe >= 0.3.3 && < 0.4,+ transformers >= 0.2 && < 0.4 Exposed-Modules: Control.Error, Control.Error.Safe,