[commit: ghc] master: Add ExceptionMonad instance for IOEnv. (adea827)

git at git.haskell.org git at git.haskell.org
Wed Jul 22 20:03:47 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/adea827955c714140e862fe86f94579c55321aab/ghc

>---------------------------------------------------------------

commit adea827955c714140e862fe86f94579c55321aab
Author: Edward Z. Yang <ezyang at cs.stanford.edu>
Date:   Tue Jul 21 17:05:16 2015 -0700

    Add ExceptionMonad instance for IOEnv.
    
    Signed-off-by: Edward Z. Yang <ezyang at cs.stanford.edu>


>---------------------------------------------------------------

adea827955c714140e862fe86f94579c55321aab
 compiler/utils/IOEnv.hs | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/compiler/utils/IOEnv.hs b/compiler/utils/IOEnv.hs
index 1ddf170..fae3b96 100644
--- a/compiler/utils/IOEnv.hs
+++ b/compiler/utils/IOEnv.hs
@@ -93,6 +93,16 @@ instance Show IOEnvFailure where
 
 instance Exception IOEnvFailure
 
+instance ExceptionMonad (IOEnv a) where
+  gcatch act handle =
+      IOEnv $ \s -> unIOEnv act s `gcatch` \e -> unIOEnv (handle e) s
+  gmask f =
+      IOEnv $ \s -> gmask $ \io_restore ->
+                             let
+                                g_restore (IOEnv m) = IOEnv $ \s -> io_restore (m s)
+                             in
+                                unIOEnv (f g_restore) s
+
 instance ContainsDynFlags env => HasDynFlags (IOEnv env) where
     getDynFlags = do env <- getEnv
                      return $ extractDynFlags env



More information about the ghc-commits mailing list