X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Futils%2FIOEnv.hs;h=5f354f0e4d96ee84d14bce08271b1b3cc4d8008c;hb=8ffd91b6102f4ad3111cabdf6bdb1998f257887f;hp=61345ca246aa41243a7849838f5864b4830d48be;hpb=f4ce543cff19b797d54d435dc7c804acdefca9c8;p=ghc-hetmet.git diff --git a/compiler/utils/IOEnv.hs b/compiler/utils/IOEnv.hs index 61345ca..5f354f0 100644 --- a/compiler/utils/IOEnv.hs +++ b/compiler/utils/IOEnv.hs @@ -3,6 +3,7 @@ -- -- The IO Monad with an environment -- +{-# LANGUAGE UndecidableInstances #-} module IOEnv ( IOEnv, -- Instance of Monad @@ -31,6 +32,7 @@ import Data.IORef ( IORef, newIORef, readIORef, writeIORef, modifyIORef ) import Data.Typeable import System.IO.Unsafe ( unsafeInterleaveIO ) import System.IO ( fixIO ) +import Control.Monad import MonadUtils ---------------------------------------------------------------------- @@ -132,6 +134,22 @@ unsafeInterleaveM (IOEnv m) = IOEnv (\ env -> unsafeInterleaveIO (m env)) ---------------------------------------------------------------------- +-- MonadPlus +---------------------------------------------------------------------- + +-- For use if the user has imported Control.Monad.Error from MTL +-- Requires UndecidableInstances +#if __GLASGOW_HASKELL__ > 606 +-- for some reason, this doesn't compile with GHC 6.6: +-- utils/IOEnv.hs:144:33: +-- No instance for (MonadPlus IO) +-- arising from use of `mplus' at utils/IOEnv.hs:144:33-67 +instance MonadPlus IO => MonadPlus (IOEnv env) where + mzero = IOEnv (const mzero) + m `mplus` n = IOEnv (\env -> unIOEnv m env `mplus` unIOEnv n env) +#endif + +---------------------------------------------------------------------- -- Accessing input/output ----------------------------------------------------------------------