[commit: ghc] master: Applicative instance for Ghc and GhcT (9e02b02)

git at git.haskell.org git at git.haskell.org
Thu Aug 29 07:15:24 CEST 2013


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/9e02b0260ef5c6571b3fc1482401fd9668e2e507/ghc

>---------------------------------------------------------------

commit 9e02b0260ef5c6571b3fc1482401fd9668e2e507
Author: Dan Frumin <difrumin at gmail.com>
Date:   Mon Aug 26 14:53:37 2013 +0000

    Applicative instance for Ghc and GhcT
    
    Fixes #8175.
    
    Signed-off-by: Austin Seipp <aseipp at pobox.com>


>---------------------------------------------------------------

9e02b0260ef5c6571b3fc1482401fd9668e2e507
 compiler/main/GhcMonad.hs |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/compiler/main/GhcMonad.hs b/compiler/main/GhcMonad.hs
index 66034e0..68b4e2b 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





More information about the ghc-commits mailing list