MonadCatchIO-transformers 0.0.1.0 → 0.0.2.0
raw patch · 2 files changed
+58/−13 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Control.Monad.CatchIO: bracketOnError :: (MonadCatchIO m) => m a -> (a -> m b) -> (a -> m c) -> m c
+ Control.Monad.CatchIO: bracket_ :: (MonadCatchIO m) => m a -> m b -> m c -> m c
+ Control.Monad.CatchIO: finally :: (MonadCatchIO m) => m a -> m b -> m a
Files
MonadCatchIO-transformers.cabal view
@@ -1,15 +1,16 @@ Name: MonadCatchIO-transformers-Version: 0.0.1.0+Version: 0.0.2.0 Cabal-Version: >= 1.2 License: PublicDomain Description:- Provides a monad-transformer version of the @Control.Exception.catch@- function. For this, it defines the @MonadCatchIO@ class, a subset of- @MonadIO@. It defines proper instances for most monad transformers in- the 'transformers' library.+ Provides functions to throw and catch exceptions. Unlike the functions from+ @Control.Exception@, which work in @IO@, these work in any stack of monad+ transformers (from the 'transformers' package) with @IO@ as the base monad.+ You can extend this functionality to other monads, by creating an instance+ of the @MonadCatchIO@ class. Maintainer: ariep@xs4all.nl Category: Control-Synopsis: Monad-transformer version of the Control.Exception module+Synopsis: Monad-transformer compatible version of the Control.Exception module Build-Type: Simple Library
src/Control/Monad/CatchIO.hs view
@@ -1,9 +1,17 @@-module Control.Monad.CatchIO ( MonadCatchIO(..),- E.Exception(..),- throw,- try, tryJust,- onException, bracket,- Handler(..), catches )+module Control.Monad.CatchIO+ (+ MonadCatchIO(..)+ , E.Exception(..)+ , throw+ , try, tryJust+ , Handler(..), catches+ -- * Utilities+ , bracket+ , bracket_+ , bracketOnError+ , finally+ , onException+ ) where @@ -107,4 +115,40 @@ -- | Generalized version of 'E.onException' onException :: MonadCatchIO m => m a -> m b -> m a-onException a onEx = a `catch` (\(e::E.SomeException) -> onEx >> throw e)+onException a onEx = a `catch` (\ (e :: E.SomeException) -> onEx >> throw e)++-- | A variant of 'bracket' where the return value from the first computation+-- is not required.+bracket_ :: MonadCatchIO m+ => m a -- ^ computation to run first (\"acquire resource\")+ -> m b -- ^ computation to run last (\"release resource\")+ -> m c -- ^ computation to run in-between+ -> m c -- returns the value from the in-between computation+bracket_ before after thing = block $ do+ before+ r <- unblock thing `onException` after+ after+ return r++-- | A specialised variant of 'bracket' with just a computation to run+-- afterward.+finally :: MonadCatchIO m+ => m a -- ^ computation to run first+ -> m b -- ^ computation to run afterward (even if an exception was+ -- raised)+ -> m a -- returns the value from the first computation+thing `finally` after = block $ do+ r <- unblock thing `onException` after+ after+ return r++-- | Like 'bracket', but only performs the final action if there was an+-- exception raised by the in-between computation.+bracketOnError :: MonadCatchIO m+ => m a -- ^ computation to run first (\"acquire resource\")+ -> (a -> m b) -- ^ computation to run last (\"release resource\")+ -> (a -> m c) -- ^ computation to run in-between+ -> m c -- returns the value from the in-between computation+bracketOnError before after thing = block $ do+ a <- before+ unblock (thing a) `onException` after a