add GHC.HetMet.{hetmet_kappa,hetmet_kappa_app}
[ghc-base.git] / System / IO / Error.hs
index 2b9eb7c..a026f33 100644 (file)
@@ -1,4 +1,4 @@
-{-# OPTIONS_GHC -XNoImplicitPrelude #-}
+{-# LANGUAGE CPP, NoImplicitPrelude #-}
 
 -----------------------------------------------------------------------------
 -- |
@@ -76,7 +76,9 @@ module System.IO.Error (
 
     ioError,                    -- :: IOError -> IO a
 
+    catchIOError,               -- :: IO a -> (IOError -> IO a) -> IO a
     catch,                      -- :: IO a -> (IOError -> IO a) -> IO a
+    tryIOError,                 -- :: IO a -> IO (Either IOError a)
     try,                        -- :: IO a -> IO (Either IOError a)
 
     modifyIOError,              -- :: (IOError -> IOError) -> IO a -> IO a
@@ -93,7 +95,9 @@ import Data.Maybe
 
 #ifdef __GLASGOW_HASKELL__
 import GHC.Base
-import GHC.IOBase
+import GHC.IO
+import GHC.IO.Exception
+import GHC.IO.Handle.Types
 import Text.Show
 #endif
 
@@ -126,13 +130,20 @@ import Data.Maybe (fromJust)
 import Control.Monad (MonadPlus(mplus))
 #endif
 
--- | The construct 'try' @comp@ exposes IO errors which occur within a
+-- | The construct 'tryIOError' @comp@ exposes IO errors which occur within a
 -- computation, and which are not fully handled.
 --
 -- Non-I\/O exceptions are not caught by this variant; to catch all
 -- exceptions, use 'Control.Exception.try' from "Control.Exception".
+tryIOError     :: IO a -> IO (Either IOError a)
+tryIOError f   =  catch (do r <- f
+                            return (Right r))
+                        (return . Left)
 
 #ifndef __NHC__
+{-# DEPRECATED try "Please use the new exceptions variant, Control.Exception.try" #-}
+-- | The 'try' function is deprecated. Please use the new exceptions
+-- variant, 'Control.Exception.try' from "Control.Exception", instead.
 try            :: IO a -> IO (Either IOError a)
 try f          =  catch (do r <- f
                             return (Right r))
@@ -417,6 +428,7 @@ annotateIOError ioe loc hdl path =
   ioe{ ioe_handle = hdl `mplus` ioe_handle ioe,
        ioe_location = loc, ioe_filename = path `mplus` ioe_filename ioe }
   where
+    mplus :: Maybe a -> Maybe a -> Maybe a
     Nothing `mplus` ys = ys
     xs      `mplus` _  = xs
 #endif /* __GLASGOW_HASKELL__ || __HUGS__ */
@@ -433,14 +445,16 @@ annotateIOError (NHC.PatternError loc) msg' _ _ =
 #endif
 
 #ifndef __HUGS__
--- | The 'catch' function establishes a handler that receives any 'IOError'
--- raised in the action protected by 'catch'.  An 'IOError' is caught by
--- the most recent handler established by 'catch'.  These handlers are
+-- | The 'catchIOError' function establishes a handler that receives any
+-- 'IOError' raised in the action protected by 'catchIOError'.
+-- An 'IOError' is caught by
+-- the most recent handler established by one of the exception handling
+-- functions.  These handlers are
 -- not selective: all 'IOError's are caught.  Exception propagation
 -- must be explicitly provided in a handler by re-raising any unwanted
 -- exceptions.  For example, in
 --
--- > f = catch g (\e -> if IO.isEOFError e then return [] else ioError e)
+-- > f = catchIOError g (\e -> if IO.isEOFError e then return [] else ioError e)
 --
 -- the function @f@ returns @[]@ when an end-of-file exception
 -- (cf. 'System.IO.Error.isEOFError') occurs in @g@; otherwise, the
@@ -451,6 +465,12 @@ annotateIOError (NHC.PatternError loc) msg' _ _ =
 --
 -- Non-I\/O exceptions are not caught by this variant; to catch all
 -- exceptions, use 'Control.Exception.catch' from "Control.Exception".
+catchIOError :: IO a -> (IOError -> IO a) -> IO a
+catchIOError = New.catch
+
+{-# DEPRECATED catch "Please use the new exceptions variant, Control.Exception.catch" #-}
+-- | The 'catch' function is deprecated. Please use the new exceptions
+-- variant, 'Control.Exception.catch' from "Control.Exception", instead.
 catch :: IO a -> (IOError -> IO a) -> IO a
 catch = New.catch
 #endif /* !__HUGS__ */