Permalink
Browse files

Example using an accumulator: a good test for generalisation, as we c…

…an get fusion despite the accumulation
  • Loading branch information...
1 parent cef3ca2 commit 6bf60eeb9b74bb1fc1bd96959e085e6ed3d68b47 @batterseapower committed Jul 21, 2010
Showing with 15 additions and 0 deletions.
  1. +15 −0 examples/toys/AccumulatingParam.core
View
15 examples/toys/AccumulatingParam.core
@@ -0,0 +1,15 @@
+#include "../Prelude.core"
+
+-- Example from Section 5 of "Shortcut Fusion for Accumulating Parameters & Zip-like Functions"
+-- Optimal output should be isomorphic to:
+--
+-- root c n a b = foldDU n a
+-- where
+-- foldDU n a = if a > b
+-- then n
+-- else foldlDU (c n a) (a + 1)
+root c n a b = foldl c n (enumFromTo a b)
+
+tests = [
+ (root (+) 0 1 10, 55)
+ ]

0 comments on commit 6bf60ee

Please sign in to comment.