From adea827955c714140e862fe86f94579c55321aab Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Tue, 21 Jul 2015 17:05:16 -0700 Subject: Add ExceptionMonad instance for IOEnv. Signed-off-by: Edward Z. Yang --- compiler/utils/IOEnv.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'compiler/utils/IOEnv.hs') diff --git a/compiler/utils/IOEnv.hs b/compiler/utils/IOEnv.hs index 1ddf170cf0..fae3b9634f 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 -- cgit v1.2.1