[commit: ghc] wip/oneShot: Add oneShot demo file (f9b4c5e)

git at git.haskell.org git at git.haskell.org
Thu Oct 30 09:20:09 UTC 2014


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

On branch  : wip/oneShot
Link       : http://ghc.haskell.org/trac/ghc/changeset/f9b4c5e8664bf94b4328ea11ac64e6266474fcdf/ghc

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

commit f9b4c5e8664bf94b4328ea11ac64e6266474fcdf
Author: Joachim Breitner <mail at joachim-breitner.de>
Date:   Mon Oct 6 23:04:02 2014 +0200

    Add oneShot demo file
    
    (if you remove {-# GHC_OPTIONS -fno-call-arity #-} then both functions
    have the same Core).
    
    Obviously, this patch is not meant to be merged.


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

f9b4c5e8664bf94b4328ea11ac64e6266474fcdf
 OneShotTest.hs | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/OneShotTest.hs b/OneShotTest.hs
new file mode 100644
index 0000000..b595285
--- /dev/null
+++ b/OneShotTest.hs
@@ -0,0 +1,22 @@
+{-# OPTIONS_GHC -fno-call-arity #-}
+
+module OneShotTest (foldlB, foldlA, fooA, fooB, fooC) where
+
+import GHC.Prim (oneShot)
+
+foldlA, foldlB :: (x -> a -> a) -> a -> [x] -> a
+
+foldlA k a xs = foldr (\v f a -> f (v `k` a)) id xs a
+{-# INLINEABLE foldlA #-}
+
+foldlB k a xs = foldr (\v f -> oneShot (\ a -> f (v `k` a))) id xs a
+{-# INLINEABLE foldlB #-}
+
+f :: Int -> Bool
+f 0 = True
+f 1 = False
+{-# NOINLINE f #-}
+
+fooA = foldlA (+) 0 . filter f
+fooB = foldlB (+) 0 . filter f
+fooC = foldl (+) 0 . filter f



More information about the ghc-commits mailing list