projects
/
ghc-hetmet.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
acb70e7
)
Added Applicative instance for IOEnv
author
Twan van Laarhoven
<twanvl@gmail.com>
Thu, 17 Jan 2008 16:26:44 +0000
(16:26 +0000)
committer
Twan van Laarhoven
<twanvl@gmail.com>
Thu, 17 Jan 2008 16:26:44 +0000
(16:26 +0000)
compiler/utils/IOEnv.hs
patch
|
blob
|
history
diff --git
a/compiler/utils/IOEnv.hs
b/compiler/utils/IOEnv.hs
index
a87413b
..
86d3ab2
100644
(file)
--- 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 Data.IORef ( IORef, newIORef, readIORef, writeIORef )
import System.IO.Unsafe ( unsafeInterleaveIO )
import System.IO ( fixIO )
-
+import MonadUtils
----------------------------------------------------------------------
-- Defining the monad type
----------------------------------------------------------------------
-- 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
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
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)
returnM :: a -> IOEnv env a
returnM a = IOEnv (\ env -> return a)