summaryrefslogtreecommitdiff
path: root/libraries/base/GHC/IO.hs
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/base/GHC/IO.hs')
-rw-r--r--libraries/base/GHC/IO.hs10
1 files changed, 8 insertions, 2 deletions
diff --git a/libraries/base/GHC/IO.hs b/libraries/base/GHC/IO.hs
index 9fa0aff929..1e8c74e5c1 100644
--- a/libraries/base/GHC/IO.hs
+++ b/libraries/base/GHC/IO.hs
@@ -23,7 +23,7 @@
-----------------------------------------------------------------------------
module GHC.IO (
- IO(..), unIO, failIO, liftIO,
+ IO(..), unIO, failIO, liftIO, mplusIO,
unsafePerformIO, unsafeInterleaveIO,
unsafeDupablePerformIO, unsafeDupableInterleaveIO,
noDuplicate,
@@ -45,7 +45,7 @@ import GHC.ST
import GHC.Exception
import GHC.Show
-import {-# SOURCE #-} GHC.IO.Exception ( userError )
+import {-# SOURCE #-} GHC.IO.Exception ( userError, IOError )
-- ---------------------------------------------------------------------------
-- The IO Monad
@@ -292,6 +292,12 @@ catchAny :: IO a -> (forall e . Exception e => e -> IO a) -> IO a
catchAny (IO io) handler = IO $ catch# io handler'
where handler' (SomeException e) = unIO (handler e)
+
+mplusIO :: IO a -> IO a -> IO a
+mplusIO m n = m `catchIOError` \ _ -> n
+ where catchIOError :: IO a -> (IOError -> IO a) -> IO a
+ catchIOError = catchException
+
-- | A variant of 'throw' that can only be used within the 'IO' monad.
--
-- Although 'throwIO' has a type that is an instance of the type of 'throw', the