packages feed

catch-fd (empty) → 0.1.0.0

raw patch · 4 files changed

+212/−0 lines, 4 filesdep +basedep +mtldep +transformerssetup-changed

Dependencies added: base, mtl, transformers

Files

+ Control/Monad/Catch.hs view
@@ -0,0 +1,148 @@+{-# LANGUAGE+    ConstraintKinds+  , DefaultSignatures+  , FlexibleInstances+  , FunctionalDependencies+  , MultiParamTypeClasses+  , UndecidableInstances #-}+module Control.Monad.Catch+       ( MonadThrow (..)+       , MonadCatch (..)+       , MonadError+       , mapE+       , WrappedMonadError (..)+       , WrappedMonadCatch (..)+       ) where++import Control.Exception (IOException)+import Control.Monad.Error hiding (MonadError)+import qualified Control.Monad.Error.Class as Error+import Control.Monad.Trans.Identity+import Control.Monad.Trans.List+import Control.Monad.Trans.Maybe+import Control.Monad.Trans.Reader+import qualified Control.Monad.Trans.RWS.Lazy as Lazy+import qualified Control.Monad.Trans.RWS.Strict as Strict+import qualified Control.Monad.Trans.State.Lazy as Lazy+import qualified Control.Monad.Trans.State.Strict as Strict+import qualified Control.Monad.Trans.Writer.Lazy as Lazy+import qualified Control.Monad.Trans.Writer.Strict as Strict++import Data.Monoid++class Monad m => MonadThrow e m | m -> e where+  throw :: e -> m a+  default throw :: (MonadThrow e m, MonadTrans t) => e -> t m a+  throw = lift . throw++class ( MonadThrow e m+      , Monad n+      ) => MonadCatch e m n | m -> e, n e -> m where+  catch :: m a -> (e -> n a) -> n a++type MonadError e m = (MonadThrow e m, MonadCatch e m m)++mapE :: (MonadThrow e' n, MonadCatch e m n) => (e -> e') -> m a -> n a+mapE f m = m `catch` (throw . f)++instance (Error e, Monad m) => MonadThrow e (ErrorT e m) where+  throw = throwError+instance ( Error e+         , Error e'+         , Monad m+         ) => MonadCatch e (ErrorT e m) (ErrorT e' m) where+  m `catch` h = ErrorT $ runErrorT m >>= either (runErrorT . h) (return . Right)++instance MonadThrow e m => MonadThrow e (IdentityT m)+instance MonadCatch e m n => MonadCatch e (IdentityT m) (IdentityT n) where+  m `catch` h = IdentityT $ runIdentityT m `catch` (runIdentityT . h)++instance MonadThrow e m => MonadThrow e (ListT m)+instance MonadCatch e m n => MonadCatch e (ListT m) (ListT n) where+  m `catch` h = ListT $ runListT m `catch` \ e -> runListT (h e)++instance MonadThrow e m => MonadThrow e (MaybeT m)+instance MonadCatch e m n => MonadCatch e (MaybeT m) (MaybeT n) where+  m `catch` h = MaybeT $ runMaybeT m `catch` (runMaybeT . h)++instance MonadThrow e m => MonadThrow e (ReaderT r m)+instance MonadCatch e m n => MonadCatch e (ReaderT r m) (ReaderT r n) where+  m `catch` h = ReaderT $ \ r -> runReaderT m r `catch` \ e -> runReaderT (h e) r++instance (Monoid w, MonadThrow e m) => MonadThrow e (Lazy.RWST r w s m)+instance (Monoid w, MonadCatch e m n) =>+         MonadCatch e (Lazy.RWST r w s m) (Lazy.RWST r w s n) where+  m `catch` h =+    Lazy.RWST $ \ r s -> Lazy.runRWST m r s `catch` \ e -> Lazy.runRWST (h e) r s++instance (Monoid w, MonadThrow e m) => MonadThrow e (Strict.RWST r w s m)+instance (Monoid w, MonadCatch e m n) =>+         MonadCatch e (Strict.RWST r w s m) (Strict.RWST r w s n) where+  m `catch` h = Strict.RWST $ \ r s ->+    Strict.runRWST m r s `catch` \ e -> Strict.runRWST (h e) r s++instance MonadThrow e m => MonadThrow e (Lazy.StateT s m)+instance MonadCatch e m n =>+         MonadCatch e (Lazy.StateT s m) (Lazy.StateT s n) where+  m `catch` h = Lazy.StateT $ \ s ->+    Lazy.runStateT m s `catch` \ e -> Lazy.runStateT (h e) s++instance MonadThrow e m => MonadThrow e (Strict.StateT s m)+instance MonadCatch e m n =>+         MonadCatch e (Strict.StateT s m) (Strict.StateT s n) where+  m `catch` h = Strict.StateT $ \ s ->+    Strict.runStateT m s `catch` \ e -> Strict.runStateT (h e) s++instance (Monoid w, MonadThrow e m) => MonadThrow e (Lazy.WriterT w m)+instance ( Monoid w+         , MonadCatch e m n+         ) => MonadCatch e (Lazy.WriterT w m) (Lazy.WriterT w n) where+  m `catch` h =+    Lazy.WriterT $ Lazy.runWriterT m `catch` \ e -> Lazy.runWriterT (h e)++instance ( Monoid w+         , MonadCatch e m n+         ) => MonadCatch e (Strict.WriterT w m) (Strict.WriterT w n) where+  m `catch` h =+    Strict.WriterT $ Strict.runWriterT m `catch` \ e -> Strict.runWriterT (h e)++instance (Monoid w, MonadThrow e m) => MonadThrow e (Strict.WriterT w m)++instance MonadThrow e (Either e) where+  throw = Left+instance MonadCatch e (Either e) (Either e') where+  Left e `catch` h = h e+  Right a `catch` _h = Right a++instance MonadThrow IOException IO where+  throw = throwError+instance MonadCatch IOException IO IO where+  catch = catchError++newtype WrappedMonadError m a =+  WrapMonadError { unwrapMonadError :: m a+                 }++instance Monad m => Monad (WrappedMonadError m) where+  return = WrapMonadError . return+  m >>= f = WrapMonadError $ unwrapMonadError m >>= unwrapMonadError . f++instance Error.MonadError e m => MonadThrow e (WrappedMonadError m) where+  throw = WrapMonadError . throwError+instance Error.MonadError e m =>+         MonadCatch e (WrappedMonadError m) (WrappedMonadError m) where+  m `catch` h =+    WrapMonadError $ unwrapMonadError m `catchError` (unwrapMonadError . h)++newtype WrappedMonadCatch m a =+  WrapMonadCatch { unwrapMonadCatch :: m a+                 }++instance Monad m => Monad (WrappedMonadCatch m) where+  return = WrapMonadCatch . return+  m >>= f = WrapMonadCatch $ unwrapMonadCatch m >>= unwrapMonadCatch . f++instance MonadCatch e m m => Error.MonadError e (WrappedMonadCatch m) where+  throwError = WrapMonadCatch . throw+  m `catchError` h =+    WrapMonadCatch $ unwrapMonadCatch m `catch` (unwrapMonadCatch . h)
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2012, Andy Sonnenburg++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Andy Sonnenburg nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,6 @@+module Main (main) where++import Distribution.Simple (defaultMain)++main :: IO ()+main = defaultMain
+ catch-fd.cabal view
@@ -0,0 +1,28 @@+name:                catch-fd+version:             0.1.0.0+cabal-version:       >= 1.6+synopsis:            MonadThrow and MonadCatch, using functional dependencies+description:         MonadThrow and MonadCatch, using functional dependencies+license:             BSD3+license-file:        LICENSE+author:              Andy Sonnenburg+maintainer:          Andy Sonnenburg <andy22286@gmail.com>+category:            Control+homepage:            http://github.com/sonyandy/catch-fd+bug-reports:         http://github.com/sonyandy/catch-fd/issues+build-type:          Simple++source-repository head+  type: git+  location: git://github.com/sonyandy/catch-fd.git++library+  exposed-modules: Control.Monad.Catch +  build-depends: base < 6, mtl == 2.1.*, transformers == 0.3.*+  extensions:+    ConstraintKinds+    FlexibleInstances+    FunctionalDependencies+    MultiParamTypeClasses+    UndecidableInstances+  ghc-options: -Wall