From 789321098f86fd3c4483b24372f8938f89b12312 Mon Sep 17 00:00:00 2001
From: David Feuer <David.Feuer@gmail.com>
Date: Wed, 1 Oct 2014 15:57:27 +0200
Subject: [PATCH] Fusion rule for "foldr k z (x:build g)"

There seem to be various issues with general fold/cons and even
cons/build rules, but it seems pretty clear to me that the simple
fold/cons/build rule is a good idea. It doesn't do much for nofib
allocation, but it seems to improve some other analyses and speed
several benchmarks up. Implements #9536.
---
 libraries/base/GHC/Base.lhs | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libraries/base/GHC/Base.lhs b/libraries/base/GHC/Base.lhs
index 8b51c07645cb..f9d01b5269c2 100644
--- a/libraries/base/GHC/Base.lhs
+++ b/libraries/base/GHC/Base.lhs
@@ -788,6 +788,9 @@ augment g xs = g (:) xs
 "foldr/single"  forall k z x. foldr k z [x] = k x z
 "foldr/nil"     forall k z.   foldr k z []  = z
 
+"foldr/cons/build" forall k z x (g::forall b. (a->b->b) -> b -> b) .
+                           foldr k z (x:build g) = k x (g k z)
+
 "augment/build" forall (g::forall b. (a->b->b) -> b -> b)
                        (h::forall b. (a->b->b) -> b -> b) .
                        augment g (build h) = build (\c n -> g c (h c n))
-- 
GitLab