MonadCatchIO-transformers 0.2.2.2 → 0.3.1.3
raw patch · 4 files changed
Files
- LICENSE +31/−0
- MonadCatchIO-transformers.cabal +11/−5
- src/Control/Monad/CatchIO.hs +16/−7
- src/Control/Monad/CatchIO/Try.hs +30/−0
+ LICENSE view
@@ -0,0 +1,31 @@+The Takusen License + +Copyright 2004, Oleg Kiselyov, Alistair Bayley. +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 the copyright holder(s) nor the names of + 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 +HOLDERS 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.
MonadCatchIO-transformers.cabal view
@@ -1,13 +1,17 @@ Name: MonadCatchIO-transformers-Version: 0.2.2.2+Version: 0.3.1.3 Cabal-Version: >= 1.6-License: PublicDomain+License: BSD3+License-file: LICENSE Description: 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.+ + 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@@ -15,14 +19,16 @@ Source-repository head Type: darcs- Location: http://patch-tag.com/r/AriePeterson/MonadCatchIO-transformers+ Location: http://hub.darcs.net/AriePeterson/MonadCatchIO-transformers Library Build-Depends:- base == 4.*,+ base < 4.9, extensible-exceptions == 0.1.*,- transformers == 0.2.*+ transformers >= 0.2 && < 0.5,+ 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)