diff options
author | Dan Frumin <difrumin@gmail.com> | 2013-08-26 14:53:37 +0000 |
---|---|---|
committer | Austin Seipp <aseipp@pobox.com> | 2013-08-28 20:15:47 -0500 |
commit | 9e02b0260ef5c6571b3fc1482401fd9668e2e507 (patch) | |
tree | c28dbd3707be8f35c7ecb046462d4db0a8564ae9 /compiler/main/GhcMonad.hs | |
parent | 98b0d05de35bd531102d832f3108050549fd781f (diff) | |
download | haskell-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.hs | 8 |
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 |