[commit: ghc] master: template-haskell: MRP-refactor Applicative/Monad instances (c6781a5)

git at git.haskell.org git at git.haskell.org
Sun Oct 18 08:52:43 UTC 2015


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

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

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

commit c6781a5064049e0a7c17c1f2239567a3c44955af
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date:   Sun Oct 18 09:20:30 2015 +0200

    template-haskell: MRP-refactor Applicative/Monad instances
    
    As `template-haskell` is compiled by stage1+ GHC only, we can
    drop the explicit `return` definition rightaway.


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

c6781a5064049e0a7c17c1f2239567a3c44955af
 libraries/template-haskell/Language/Haskell/TH/PprLib.hs | 3 +--
 libraries/template-haskell/Language/Haskell/TH/Syntax.hs | 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/libraries/template-haskell/Language/Haskell/TH/PprLib.hs b/libraries/template-haskell/Language/Haskell/TH/PprLib.hs
index 8019e48..e398094 100644
--- a/libraries/template-haskell/Language/Haskell/TH/PprLib.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/PprLib.hs
@@ -154,11 +154,10 @@ instance Functor PprM where
       fmap = liftM
 
 instance Applicative PprM where
-      pure = return
+      pure x = PprM $ \s -> (x, s)
       (<*>) = ap
 
 instance Monad PprM where
-    return x = PprM $ \s -> (x, s)
     m >>= k  = PprM $ \s -> let (x, s') = runPprM m s
                             in runPprM (k x) s'
 
diff --git a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
index 8d56a98..607e6da 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
@@ -159,9 +159,8 @@ runQ :: Quasi m => Q a -> m a
 runQ (Q m) = m
 
 instance Monad Q where
-  return x   = Q (return x)
   Q m >>= k  = Q (m >>= \x -> unQ (k x))
-  Q m >> Q n = Q (m >> n)
+  (>>) = (*>)
   fail s     = report True s >> Q (fail "Q monad failure")
 
 instance Functor Q where
@@ -170,6 +169,7 @@ instance Functor Q where
 instance Applicative Q where
   pure x = Q (pure x)
   Q f <*> Q x = Q (f <*> x)
+  Q m *> Q n = Q (m *> n)
 
 -----------------------------------------------------
 --



More information about the ghc-commits mailing list