packages feed

control-monad-exception 0.6 → 0.8.0

raw patch · 6 files changed

+34/−243 lines, 6 filesdep +failuredep −control-monad-failuredep −monads-fddep −mtlPVP ok

version bump matches the API change (PVP)

Dependencies added: failure

Dependencies removed: control-monad-failure, monads-fd, mtl, transformers

API changes (from Hackage documentation)

- Control.Monad.Exception.Base: NothingException :: NothingException
- Control.Monad.Exception.Base: class Try m l
- Control.Monad.Exception.Base: data NothingException
- Control.Monad.Exception.Base: instance (Exception e, Throws e l) => Try (Either e) l
- Control.Monad.Exception.Base: instance (Exception e, Throws e l, Monad m) => MonadFailure e (EMT l m)
- Control.Monad.Exception.Base: instance (Exception e, Throws e l, Monad m) => WrapFailure e (EMT l m)
- Control.Monad.Exception.Base: instance (Monad m, Try m l) => Try (EMT l m) l
- Control.Monad.Exception.Base: instance (Throws NothingException l) => Try Maybe l
- Control.Monad.Exception.Base: instance Exception NothingException
- Control.Monad.Exception.Base: instance Show NothingException
- Control.Monad.Exception.Base: instance Typeable NothingException
- Control.Monad.Exception.Base: try :: (Try m l, Monad m') => m a -> EMT l m' a
- Control.Monad.Exception.MonadsFD: catch :: (Exception e, Monad m) => EMT (Caught e l) m a -> (e -> EMT l m a) -> EMT l m a
- Control.Monad.Exception.MonadsFD: instance (Error e, Monad m) => MonadCatch e (ErrorT e m) (ErrorT e m)
- Control.Monad.Exception.MonadsFD: instance (MonadCatch e m m') => MonadCatch e (ListT m) (ListT m')
- Control.Monad.Exception.MonadsFD: instance (MonadCatch e m m') => MonadCatch e (ReaderT r m) (ReaderT r m')
- Control.Monad.Exception.MonadsFD: instance (MonadCatch e m m') => MonadCatch e (StateT s m) (StateT s m')
- Control.Monad.Exception.MonadsFD: instance (MonadCont m) => MonadCont (EMT l m)
- Control.Monad.Exception.MonadsFD: instance (MonadReader r m) => MonadReader r (EMT l m)
- Control.Monad.Exception.MonadsFD: instance (MonadState s m) => MonadState s (EMT l m)
- Control.Monad.Exception.MonadsFD: instance (Monoid w, MonadCatch e m m') => MonadCatch e (RWST r w s m) (RWST r w s m')
- Control.Monad.Exception.MonadsFD: instance (Monoid w, MonadCatch e m m') => MonadCatch e (WriterT w m) (WriterT w m')
- Control.Monad.Exception.MonadsFD: instance (Monoid w, MonadRWS r w s m) => MonadRWS r w s (EMT l m)
- Control.Monad.Exception.MonadsFD: instance (Monoid w, MonadWriter w m) => MonadWriter w (EMT l m)
- Control.Monad.Exception.MonadsFD: instance (Throws MonadZeroException l) => MonadPlus (EM l)
- Control.Monad.Exception.MonadsFD: instance (Throws SomeException l, MonadIO m) => MonadIO (EMT l m)
- Control.Monad.Exception.MonadsFD: instance MonadTrans (EMT l)
- Control.Monad.Exception.Mtl: catch :: (Exception e, Monad m) => EMT (Caught e l) m a -> (e -> EMT l m a) -> EMT l m a
- Control.Monad.Exception.Mtl: instance (Error e, Monad m) => MonadCatch e (ErrorT e m) (ErrorT e m)
- Control.Monad.Exception.Mtl: instance (MonadCatch e m m') => MonadCatch e (ListT m) (ListT m')
- Control.Monad.Exception.Mtl: instance (MonadCatch e m m') => MonadCatch e (ReaderT r m) (ReaderT r m')
- Control.Monad.Exception.Mtl: instance (MonadCatch e m m') => MonadCatch e (StateT s m) (StateT s m')
- Control.Monad.Exception.Mtl: instance (MonadCont m) => MonadCont (EMT l m)
- Control.Monad.Exception.Mtl: instance (MonadReader r m) => MonadReader r (EMT l m)
- Control.Monad.Exception.Mtl: instance (MonadState s m) => MonadState s (EMT l m)
- Control.Monad.Exception.Mtl: instance (Monoid w, MonadCatch e m m') => MonadCatch e (RWST r w s m) (RWST r w s m')
- Control.Monad.Exception.Mtl: instance (Monoid w, MonadCatch e m m') => MonadCatch e (WriterT w m) (WriterT w m')
- Control.Monad.Exception.Mtl: instance (Monoid w, MonadRWS r w s m) => MonadRWS r w s (EMT l m)
- Control.Monad.Exception.Mtl: instance (Monoid w, MonadWriter w m) => MonadWriter w (EMT l m)
- Control.Monad.Exception.Mtl: instance (Throws MonadZeroException l) => MonadPlus (EM l)
- Control.Monad.Exception.Mtl: instance (Throws SomeException l, MonadIO m) => MonadIO (EMT l m)
- Control.Monad.Exception.Mtl: instance MonadTrans (EMT l)
+ Control.Monad.Exception: SomeException :: e -> SomeException
+ Control.Monad.Exception: class (Typeable e, Show e) => Exception e
+ Control.Monad.Exception: class Failure e f :: (* -> *)
+ Control.Monad.Exception: class (Monad f, Applicative f, Failure e f) => MonadFailure e f :: (* -> *)
+ Control.Monad.Exception: class (Monad m) => MonadLoc m :: (* -> *)
+ Control.Monad.Exception: class Typeable a
+ Control.Monad.Exception: class (Failure e f) => WrapFailure e f :: (* -> *)
+ Control.Monad.Exception: data SomeException :: *
+ Control.Monad.Exception: failure :: (Failure e f) => e -> f v
+ Control.Monad.Exception: fromException :: (Exception e) => SomeException -> Maybe e
+ Control.Monad.Exception: mplusDefault :: (Monad m) => EMT l m a -> EMT l m a -> EMT l m a
+ Control.Monad.Exception: toException :: (Exception e) => e -> SomeException
+ Control.Monad.Exception: typeOf :: (Typeable a) => a -> TypeRep
+ Control.Monad.Exception: withLoc :: (MonadLoc m) => String -> m a -> m a
+ Control.Monad.Exception: withLocTH :: Q Exp
+ Control.Monad.Exception: wrapFailure :: (WrapFailure e f) => (forall eIn. (Exception eIn) => eIn -> e) -> f a -> f a
+ Control.Monad.Exception.Base: instance (Exception e, Throws e l, Failure e m, Monad m) => WrapFailure e (EMT l m)
+ Control.Monad.Exception.Base: instance (Exception e, Throws e l, Monad m, Failure e m) => Failure e (EMT l m)
+ Control.Monad.Exception.Base: instance (Throws MonadZeroException l) => MonadPlus (EM l)
+ Control.Monad.Exception.Base: mplusDefault :: (Monad m) => EMT l m a -> EMT l m a -> EMT l m a
+ Control.Monad.Exception.Catch: SomeException :: e -> SomeException
+ Control.Monad.Exception.Catch: class (Typeable e, Show e) => Exception e
+ Control.Monad.Exception.Catch: data SomeException :: *
+ Control.Monad.Exception.Catch: fromException :: (Exception e) => SomeException -> Maybe e
+ Control.Monad.Exception.Catch: toException :: (Exception e) => e -> SomeException
- Control.Monad.Exception: class Try m l
+ Control.Monad.Exception: class Try f :: (* -> *) where { type family Error f :: (* -> *) :: *; }
- Control.Monad.Exception: data NothingException
+ Control.Monad.Exception: data NothingException :: *
- Control.Monad.Exception: try :: (Try m l, Monad m') => m a -> EMT l m' a
+ Control.Monad.Exception: try :: (Try f, ApplicativeFailure (Error f) f') => f a -> f' a

Files

Control/Monad/Exception.hs view
@@ -65,27 +65,24 @@ -- ** The Throws type class    Throws, Caught, --- ** The Try type class for absorbing other failure types-    Try(..), NothingException(..),- -- * Exception primitives       throw, rethrow, Control.Monad.Exception.Base.catch, Control.Monad.Exception.Base.catchWithSrcLoc,     finally, onException, bracket, wrapException,      showExceptionWithTrace,-    FailException(..), MonadZeroException(..),+    FailException(..), MonadZeroException(..), mplusDefault,  -- * Reexports     Exception(..), SomeException(..), Typeable(..),-    MonadFailure(..), WrapFailure(..),+    Try(..), NothingException(..),+    Failure(..), MonadFailure, WrapFailure(..),     MonadLoc(..), withLocTH ) where -import Control.Exception (Exception(..), SomeException(..)) import Control.Monad.Exception.Base import Control.Monad.Exception.Catch import Control.Monad.Exception.Throws-import Control.Monad.Failure+import Control.Failure import Control.Monad.Loc import Data.Typeable @@ -114,13 +111,6 @@ Also, 'tryEMT' allows you to run a computation regardless of the exceptions it throws. -} -{- $unexplicit-An exception @E@ can be made unexplicit: @E@ will not appear in the list-   of exceptions. To do so include the following instance in your code:-->  instance Throws E l---}  {- $stacktraces  Stack traces are provided via the "MonadLoc" package.
Control/Monad/Exception/Base.hs view
@@ -1,9 +1,8 @@ {-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE ExistentialQuantification, ScopedTypeVariables #-}-{-# LANGUAGE UndecidableInstances #-}-{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE FlexibleContexts, FlexibleInstances, TypeSynonymInstances #-} {-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE CPP #-}+{-# LANGUAGE PatternGuards #-}  {-| A Monad Transformer for explicitly typed checked exceptions.@@ -48,7 +47,7 @@ import Control.Applicative import Control.Monad.Exception.Catch import Control.Monad.Loc-import Control.Monad.Failure.Class+import Control.Failure import Control.Monad.Fix import Data.Typeable import Text.PrettyPrint@@ -104,10 +103,10 @@   pure  = return   (<*>) = ap -instance (Exception e, Throws e l, Monad m) => MonadFailure e (EMT l m) where+instance (Exception e, Throws e l, Monad m, Failure e m) => Failure e (EMT l m) where   failure = throw -instance (Exception e, Throws e l, Monad m) => WrapFailure e (EMT l m) where+instance (Exception e, Throws e l, Failure e m, Monad m) => WrapFailure e (EMT l m) where   wrapFailure mkE m       = EMT $ do           v <- unEMT m@@ -234,23 +233,9 @@   return = Identity   Identity a >>= f = f a --- -------------------------------------------------- The Try class for absorbing other error monads--- ------------------------------------------------data NothingException = NothingException deriving (Typeable, Show)-instance Exception NothingException--class Try m l where-   {- | The purpose of 'try' is to combine 'EMT' with other failure handling data types.-        'try' accepts a failing computation and turns it into an 'EMT' computation.-         The instances provided allow you to 'try' on 'Maybe' and 'Either' computations.-   -}-   try :: Monad m' => m a -> EMT l m' a--instance Throws NothingException l => Try Maybe l where try = maybe (throw NothingException) return-instance (Exception e, Throws e l) => Try (Either e) l where try = either throw return--instance (Monad m, Try m l) => Try (EMT l m) l where try = join . fmap (EMT . return) .try . unEMT+instance (Throws MonadZeroException l) => MonadPlus (EM l) where+  mzero = throw MonadZeroException+  mplus = mplusDefault  -- ----------- -- Exceptions@@ -264,7 +249,13 @@ data MonadZeroException = MonadZeroException deriving (Show, Typeable) instance Exception MonadZeroException -+-- | This function may be used as a value for 'mplus' in 'MonadPlus'+mplusDefault :: Monad m => EMT l m a -> EMT l m a -> EMT l m a+mplusDefault emt1 emt2 = EMT$ do+                     v1 <- unEMT emt1+                     case v1 of+                       Left (_,CheckedException e) | Just MonadZeroException <- fromException e -> unEMT emt2+                       _  -> return v1 -- other  mapLeft :: (a -> b) -> Either a r -> Either b r
− Control/Monad/Exception/MonadsFD.hs
@@ -1,85 +0,0 @@-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE TypeSynonymInstances #-}-{-# LANGUAGE PackageImports #-}---- | 'EMT' liftings for the classes in the monads-fd package-module Control.Monad.Exception.MonadsFD (module Control.Monad.Exception, Control.Monad.Exception.catch-                                        ) where--import qualified Control.Exception as CE--import qualified Control.Monad.Exception-import Control.Monad.Exception hiding (catch)-import Control.Monad.Exception.Catch-import Control.Monad.Exception.Throws-import "monads-fd" Control.Monad.Cont.Class-import "monads-fd" Control.Monad.RWS.Class--import Control.Monad-import "transformers" Control.Monad.Trans--import Control.Monad.Trans.Error-import Control.Monad.Trans.List-import Control.Monad.Trans.Reader (ReaderT(..))-import Control.Monad.Trans.State (StateT(..))-import Control.Monad.Trans.Writer (WriterT(..))-import Control.Monad.Trans.RWS (RWST(..))--import Data.Monoid-import Prelude hiding (catch)--instance (Throws MonadZeroException l) => MonadPlus (EM l) where-  mzero = throw MonadZeroException-  mplus emt1 emt2 = EMT$ do-                     v1 <- unEMT emt1-                     case v1 of-                       Left _  -> unEMT emt2-                       Right _ -> return v1---instance MonadTrans (EMT l) where lift = EMT . liftM Right--instance (Throws SomeException l, MonadIO m) => MonadIO (EMT l m) where-  liftIO m = EMT (liftIO m') where-      m' = liftM Right m-            `CE.catch`-           \(e::SomeException) -> return (Left ([], CheckedException e))--instance MonadCont m => MonadCont (EMT l m) where-  callCC f = EMT $ callCC $ \c -> unEMT (f (\a -> EMT $ c (Right a)))--instance MonadReader r m => MonadReader r (EMT l m) where-  ask = lift ask-  local f m = EMT (local f (unEMT m))--instance MonadState s m => MonadState s (EMT l m) where-  get = lift get-  put = lift . put--instance (Monoid w, MonadWriter w m) => MonadWriter w (EMT l m) where-  tell   = lift . tell-  listen m = EMT $ do-               (res, w) <- listen (unEMT m)-               return (fmap (\x -> (x,w)) res)-  pass m   = EMT $ pass $ do-               a <- unEMT m-               case a of-                 Left  l     -> return (Left l, id)-                 Right (r,f) -> return (Right r, f)--instance (Monoid w, MonadRWS r w s m) => MonadRWS r w s (EMT l m)----- MonadCatch Instances--- ---------------------------------------------------------------------------- instance (Error e) => MonadCatch e (Either e) (Either e) where catch m h = either h Right m-instance (Error e, Monad m) => MonadCatch e (ErrorT e m) (ErrorT e m) where catch = catchError--instance MonadCatch e m m' => MonadCatch e (ListT m) (ListT m') where catch (ListT m) h = ListT (catch m (runListT . h))-instance MonadCatch e m m' => MonadCatch e (ReaderT r m) (ReaderT r m') where catch (ReaderT m) h = ReaderT (\s -> catch (m s) ((`runReaderT` s) . h))--instance (Monoid w, MonadCatch e m m') => MonadCatch e (WriterT w m) (WriterT w m') where catch (WriterT m) h = WriterT (catch m (runWriterT . h))--instance MonadCatch e m m' => MonadCatch e (StateT s m) (StateT s m') where catch (StateT m) h = StateT (\s -> catch (m s) ((`runStateT` s) . h))--instance (Monoid w, MonadCatch e m m') => MonadCatch e (RWST r w s m) (RWST r w s m') where catch (RWST m) h = RWST (\r s -> catch (m r s) ((\m -> runRWST m r s) . h))
− Control/Monad/Exception/Mtl.hs
@@ -1,82 +0,0 @@-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE TypeSynonymInstances #-}-{-# LANGUAGE PackageImports #-}-{-# LANGUAGE UndecidableInstances #-}---- | 'EMT' liftings for the classes in the Monad Transformer Library-module Control.Monad.Exception.Mtl (module Control.Monad.Exception, Control.Monad.Exception.catch) where--import qualified Control.Exception as CE--import qualified Control.Monad.Exception-import Control.Monad.Exception hiding (catch)-import Control.Monad.Exception.Catch as Catch-import Control.Monad.Exception.Throws-import "mtl" Control.Monad.Cont.Class-import "mtl" Control.Monad.Error-import "mtl" Control.Monad.List-import "mtl" Control.Monad.Reader-import "mtl" Control.Monad.State-import "mtl" Control.Monad.Writer-import "mtl" Control.Monad.RWS-import Data.Monoid-import Prelude hiding (catch)--instance (Throws MonadZeroException l) => MonadPlus (EM l) where-  mzero = throw MonadZeroException-  mplus emt1 emt2 = EMT$ do-                     v1 <- unEMT emt1-                     case v1 of-                       Left _  -> unEMT emt2-                       Right _ -> return v1---instance MonadTrans (EMT l) where lift = EMT . liftM Right--instance (Throws SomeException l, MonadIO m) => MonadIO (EMT l m) where-  liftIO m = EMT (liftIO m') where-      m' = liftM Right m-            `CE.catch`-           \(e::SomeException) -> return (Left ([], CheckedException e))--instance MonadCont m => MonadCont (EMT l m) where-  callCC f = EMT $ callCC $ \c -> unEMT (f (\a -> EMT $ c (Right a)))--instance MonadReader r m => MonadReader r (EMT l m) where-  ask = lift ask-  local f m = EMT (local f (unEMT m))--instance MonadState s m => MonadState s (EMT l m) where-  get = lift get-  put = lift . put--instance (Monoid w, MonadWriter w m) => MonadWriter w (EMT l m) where-  tell   = lift . tell-  listen m = EMT $ do-               (res, w) <- listen (unEMT m)-               return (fmap (\x -> (x,w)) res)-  pass m   = EMT $ pass $ do-               a <- unEMT m-               case a of-                 Left  l     -> return (Left l, id)-                 Right (r,f) -> return (Right r, f)--instance (Monoid w, MonadRWS r w s m) => MonadRWS r w s (EMT l m)------ MonadCatch Instances--- ----------------------------------------------------------------------------- Commented out due to the problem of duplicated Monad instances for Either--- instance (Error e) => MonadCatch e (Either e) (Either e) where catch m h = either h Right m-instance (Error e, Monad m) => MonadCatch e (ErrorT e m) (ErrorT e m) where catch = catchError--instance MonadCatch e m m' => MonadCatch e (ListT m) (ListT m') where catch (ListT m) h = ListT (Catch.catch m (runListT . h))-instance MonadCatch e m m' => MonadCatch e (ReaderT r m) (ReaderT r m') where catch (ReaderT m) h = ReaderT (\s -> Catch.catch (m s) ((`runReaderT` s) . h))--instance (Monoid w, MonadCatch e m m') => MonadCatch e (WriterT w m) (WriterT w m') where catch (WriterT m) h = WriterT (Catch.catch m (runWriterT . h))--instance MonadCatch e m m' => MonadCatch e (StateT s m) (StateT s m') where catch (StateT m) h = StateT (\s -> Catch.catch (m s) ((`runStateT` s) . h))--instance (Monoid w, MonadCatch e m m') => MonadCatch e (RWST r w s m) (RWST r w s m') where catch (RWST m) h = RWST (\r s -> Catch.catch (m r s) ((\m -> runRWST m r s) . h))
Control/Monad/Exception/Throws.hs view
@@ -24,12 +24,9 @@ {-| @Throws@ is a type level binary relationship     used to model a list of exceptions. -    There are two cases in which the user may want-    to add further instances to @Throws@.--     1. To encode subtyping.--     2. To declare an exception as unexplicit (a programming error).+    There is only one case in which the user must+    add further instances to @Throws@, and that is+    to encode the hierarchy of exceptions.      [/Subtyping/]      As there is no way to automatically infer@@ -39,7 +36,7 @@      For example,      the following instance encodes that @MyFileNotFoundException@ is      a subexception of @MyIOException@ :-     +  > instance Throws MyFileNotFoundException (Caught MyIOException l)      'Throws' is not a transitive relation and every ancestor relation@@ -56,11 +53,6 @@      'SomeException' is automatically       an ancestor of every other exception type. -    [/Programming Errors/]-     In order to declare an exception @E@ as a programming error, which should-     not be explicit nor checked, use a 'Throws' instance as follows:-->    instance Throws e l -}  class Exception e => Throws e l
control-monad-exception.cabal view
@@ -1,5 +1,5 @@ name: control-monad-exception-version: 0.6+version: 0.8.0 Cabal-Version:  >= 1.6 build-type: Simple license: PublicDomain@@ -44,8 +44,6 @@   .     * Support for selective unchecked exceptions (via 'Control.Monad.Exception.UncaughtException').   .-    * Support for selective unexplicit exceptions.-  .     * Support for exception call traces via 'Control.Monad.Loc.MonadLoc'. /Example:/   .   >@@ -69,21 +67,15 @@ stability: experimental tested-with: GHC ==6.10.3 -Flag mtl-  description: Provide mtl instances-  default: True --Flag monadsfd-  description: Provide monads-fd instances-  default: True - Flag extensibleExceptions   description: Use extensible-exception package   default: False  Library   buildable: True -  build-depends: control-monad-failure, monadloc, pretty+  build-depends: failure+               , monadloc+               , pretty    if flag(extensibleExceptions)     build-depends:@@ -93,28 +85,21 @@     build-depends:       base >= 4 && < 5 -  if flag(mtl)-    cpp-options: -DMTL-    build-depends: mtl-    exposed-modules : Control.Monad.Exception.Mtl--  if flag(monadsfd)-    cpp-options: -DMONADSFD-    build-depends: transformers, monads-fd-    exposed-modules : Control.Monad.Exception.MonadsFD--  extensions:  MultiParamTypeClasses, -               FunctionalDependencies,+  extensions:  MultiParamTypeClasses,+               ScopedTypeVariables,+               FlexibleContexts,                FlexibleInstances,+               TypeSynonymInstances,                EmptyDataDecls,                DeriveDataTypeable,-               UndecidableInstances+               PatternGuards    exposed-modules:      Control.Monad.Exception      Control.Monad.Exception.Base      Control.Monad.Exception.Catch      Control.Monad.Exception.Throws+   ghc-options: -Wall -fno-warn-name-shadowing -fno-warn-orphans