summaryrefslogtreecommitdiff
path: root/compiler/main/GhcMonad.hs
diff options
context:
space:
mode:
authorDan Frumin <difrumin@gmail.com>2013-08-26 14:53:37 +0000
committerAustin Seipp <aseipp@pobox.com>2013-08-28 20:15:47 -0500
commit9e02b0260ef5c6571b3fc1482401fd9668e2e507 (patch)
treec28dbd3707be8f35c7ecb046462d4db0a8564ae9 /compiler/main/GhcMonad.hs
parent98b0d05de35bd531102d832f3108050549fd781f (diff)
downloadhaskell-9e02b0260ef5c6571b3fc1482401fd9668e2e507.tar.gz
Applicative instance for Ghc and GhcT
Fixes #8175. Signed-off-by: Austin Seipp <aseipp@pobox.com>
Diffstat (limited to 'compiler/main/GhcMonad.hs')
-rw-r--r--compiler/main/GhcMonad.hs8
1 files changed, 8 insertions, 0 deletions
diff --git a/compiler/main/GhcMonad.hs b/compiler/main/GhcMonad.hs
index 66034e0b50..68b4e2b2a2 100644
--- a/compiler/main/GhcMonad.hs
+++ b/compiler/main/GhcMonad.hs
@@ -97,6 +97,10 @@ data Session = Session !(IORef HscEnv)
instance Functor Ghc where
fmap f m = Ghc $ \s -> f `fmap` unGhc m s
+instance Applicative Ghc where
+ pure = return
+ g <*> m = do f <- g; a <- m; return (f a)
+
instance Monad Ghc where
return a = Ghc $ \_ -> return a
m >>= g = Ghc $ \s -> do a <- unGhc m s; unGhc (g a) s
@@ -157,6 +161,10 @@ liftGhcT m = GhcT $ \_ -> m
instance Functor m => Functor (GhcT m) where
fmap f m = GhcT $ \s -> f `fmap` unGhcT m s
+instance Applicative m => Applicative (GhcT m) where
+ pure x = GhcT $ \_ -> pure x
+ g <*> m = GhcT $ \s -> unGhcT g s <*> unGhcT m s
+
instance Monad m => Monad (GhcT m) where
return x = GhcT $ \_ -> return x
m >>= k = GhcT $ \s -> do a <- unGhcT m s; unGhcT (k a) s