MonadCatchIO-transformers 0.3.0.0 → 0.3.1.0
raw patch · 3 files changed
+54/−10 lines, 3 filesdep +monads-tfdep ~base
Dependencies added: monads-tf
Dependency ranges changed: base
Files
- MonadCatchIO-transformers.cabal +8/−3
- src/Control/Monad/CatchIO.hs +16/−7
- src/Control/Monad/CatchIO/Try.hs +30/−0
MonadCatchIO-transformers.cabal view
@@ -1,5 +1,5 @@ Name: MonadCatchIO-transformers-Version: 0.3.0.0+Version: 0.3.1.0 Cabal-Version: >= 1.6 License: BSD3 License-file: LICENSE@@ -9,6 +9,9 @@ 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.+ + Warning: this package is deprecated. Use the 'exceptions' package instead,+ if possible. Maintainer: ariep@xs4all.nl Category: Control Synopsis: Monad-transformer compatible version of the Control.Exception module@@ -20,10 +23,12 @@ Library Build-Depends:- base == 4.*,+ base < 4.8, extensible-exceptions == 0.1.*,- transformers >= 0.2 && < 0.4+ transformers >= 0.2 && < 0.4,+ monads-tf == 0.1.* Exposed-Modules: Control.Monad.CatchIO+ Control.Monad.CatchIO.Try Hs-Source-Dirs: src Ghc-options: -Wall
src/Control/Monad/CatchIO.hs view
@@ -1,4 +1,14 @@-{-# LANGUAGE ExistentialQuantification, ScopedTypeVariables #-}+{-# LANGUAGE ExistentialQuantification, ScopedTypeVariables, MagicHash #-}+-- | Warning: this module is /deprecated/.+-- +-- Please consider using the package+-- <http://hackage.haskell.org/package/exceptions exceptions>+-- instead, if possible.+-- +-- The functions @block@ and @unblock@, which are part of the @MonadCatchIO@+-- class, have known problems. The IO instances of these functions, which are+-- provided by the base library, have been deprecated for some time, and have+-- been removed in base-4.7. module Control.Monad.CatchIO ( MonadCatchIO(..)@@ -37,22 +47,21 @@ import Data.Monoid (Monoid) +import GHC.Base (maskAsyncExceptions#)+import GHC.IO (unsafeUnmask,IO(IO)) + class MonadIO m => MonadCatchIO m where -- | Generalized version of 'E.catch' catch :: E.Exception e => m a -> (e -> m a) -> m a- - -- | Generalized version of 'E.block' block :: m a -> m a- - -- | Generalized version of 'E.unblock' unblock :: m a -> m a instance MonadCatchIO IO where catch = E.catch- block = E.block- unblock = E.unblock+ block = \ (IO io) -> IO $ maskAsyncExceptions# io+ unblock = unsafeUnmask -- | Warning: this instance is somewhat contentious. --
+ src/Control/Monad/CatchIO/Try.hs view
@@ -0,0 +1,30 @@+{-# LANGUAGE FlexibleContexts #-}+module Control.Monad.CatchIO.Try+ (+ tryIO+ , eitherIO+{- + , MonadCatchIO+ , MonadIO+ , liftIO+ , MonadError+ , Error+ , ErrorType+ , throwError+ , strMsg+ , ErrorT+ , runErrorT-}+ ) where+++import Control.Exception (IOException)+import Control.Monad.CatchIO (MonadCatchIO,tryJust)+import Control.Monad.Trans.Error (strMsg)+import Control.Monad.Error (MonadError,Error,ErrorType,throwError,MonadIO,liftIO)+++tryIO :: (Error (ErrorType m),MonadError m,MonadCatchIO m,Functor m) => IO a -> m a+tryIO = (=<<) (either (throwError . strMsg . show) return) . eitherIO . liftIO++eitherIO :: (MonadCatchIO m,Functor m) => m a -> m (Either IOException a)+eitherIO = tryJust (Just :: IOException -> Maybe IOException)