From 92478f77bb46576b9a652acbc4dd3e92c3a1fb06 Mon Sep 17 00:00:00 2001 From: Twan van Laarhoven Date: Thu, 17 Jan 2008 16:26:44 +0000 Subject: [PATCH] Added Applicative instance for IOEnv --- compiler/utils/IOEnv.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/compiler/utils/IOEnv.hs b/compiler/utils/IOEnv.hs index a87413b..86d3ab2 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) -- 1.7.10.4