summaryrefslogtreecommitdiff
path: root/compiler/utils/IOEnv.hs
diff options
context:
space:
mode:
authorTwan van Laarhoven <twanvl@gmail.com>2008-01-17 16:26:44 +0000
committerTwan van Laarhoven <twanvl@gmail.com>2008-01-17 16:26:44 +0000
commit92478f77bb46576b9a652acbc4dd3e92c3a1fb06 (patch)
tree6cb6268450be60f681f86f47d9b7463f443e6e0b /compiler/utils/IOEnv.hs
parentacb70e7c53a81ffea471d3bd6fb75c12e6bb2a37 (diff)
downloadhaskell-92478f77bb46576b9a652acbc4dd3e92c3a1fb06.tar.gz
Added Applicative instance for IOEnv
Diffstat (limited to 'compiler/utils/IOEnv.hs')
-rw-r--r--compiler/utils/IOEnv.hs16
1 files changed, 10 insertions, 6 deletions
diff --git a/compiler/utils/IOEnv.hs b/compiler/utils/IOEnv.hs
index a87413b347..86d3ab2df9 100644
--- a/compiler/utils/IOEnv.hs
+++ b/compiler/utils/IOEnv.hs
@@ -38,7 +38,7 @@ import Panic ( try, tryUser, tryMost, Exception(..) )
import Data.IORef ( IORef, newIORef, readIORef, writeIORef )
import System.IO.Unsafe ( unsafeInterleaveIO )
import System.IO ( fixIO )
-
+import MonadUtils
----------------------------------------------------------------------
-- Defining the monad type
@@ -49,13 +49,17 @@ newtype IOEnv env a = IOEnv (env -> IO a)
unIOEnv (IOEnv m) = m
instance Monad (IOEnv m) where
- (>>=) = thenM
- (>>) = thenM_
- return = returnM
- fail s = failM -- Ignore the string
+ (>>=) = thenM
+ (>>) = thenM_
+ return = returnM
+ fail s = failM -- Ignore the string
+
+instance Applicative (IOEnv m) where
+ pure = returnM
+ IOEnv f <*> IOEnv x = IOEnv (\ env -> f env <*> x env )
instance Functor (IOEnv m) where
- fmap f (IOEnv m) = IOEnv (\ env -> fmap f (m env))
+ fmap f (IOEnv m) = IOEnv (\ env -> fmap f (m env))
returnM :: a -> IOEnv env a
returnM a = IOEnv (\ env -> return a)