[commit: hsc2hs] master: Rewrite Applicative/Monad instances into normal-form (f3bcd69)

git at git.haskell.org git at git.haskell.org
Sat Oct 17 17:39:40 UTC 2015


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

On branch  : master
Link       : http://git.haskell.org/hsc2hs.git/commitdiff/f3bcd69e311620714ac83fbc3c0fa84e6b50c56a

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

commit f3bcd69e311620714ac83fbc3c0fa84e6b50c56a
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date:   Sat Oct 17 19:41:35 2015 +0200

    Rewrite Applicative/Monad instances into normal-form
    
    I.e. make sure `return` is defined in terms of `pure` rather than the
    other way round.


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

f3bcd69e311620714ac83fbc3c0fa84e6b50c56a
 CrossCodegen.hs | 4 ++--
 HSCParser.hs    | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/CrossCodegen.hs b/CrossCodegen.hs
index c1d627d..a8a7f3d 100644
--- a/CrossCodegen.hs
+++ b/CrossCodegen.hs
@@ -52,11 +52,11 @@ instance Functor TestMonad where
     fmap = liftM
 
 instance Applicative TestMonad where
-    pure = return
+    pure a = TestMonad (\_ c -> pure (Right a, c))
     (<*>) = ap
 
 instance Monad TestMonad where
-    return a = TestMonad (\_ c -> return $ (Right a, c))
+    return = pure
     x >>= fn = TestMonad (\e c -> (runTest x e c) >>=
                                       (\(a,c') -> either (\err -> return (Left err, c'))
                                                          (\result -> runTest (fn result) e c')
diff --git a/HSCParser.hs b/HSCParser.hs
index 745037f..b09213b 100644
--- a/HSCParser.hs
+++ b/HSCParser.hs
@@ -25,11 +25,11 @@ instance Functor Parser where
     fmap = liftM
 
 instance Applicative Parser where
-    pure  = return
+    pure a = Parser $ \pos s -> Success pos [] s a
     (<*>) = ap
 
 instance Monad Parser where
-    return a = Parser $ \pos s -> Success pos [] s a
+    return = pure
     Parser m >>= k =
         Parser $ \pos s -> case m pos s of
             Success pos' out1 s' a -> case k a of



More information about the ghc-commits mailing list