From 349544274787b6d587e85e75e6c754a618b813aa Mon Sep 17 00:00:00 2001
From: "naur@post11.tele.dk"
Date: Sat, 7 Feb 2009 18:14:27 +0000
Subject: [PATCH] Rules to make genericLength strict for Int/Integer lengths,
see #2962
---
Data/List.hs | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/Data/List.hs b/Data/List.hs
index 16cbeb8..bd4e14c 100644
--- a/Data/List.hs
+++ b/Data/List.hs
@@ -568,6 +568,17 @@ genericLength :: (Num i) => [b] -> i
genericLength [] = 0
genericLength (_:l) = 1 + genericLength l
+{-# RULES
+ "genericLengthInt" genericLength = (strictGenericLength :: [a] -> Int);
+ "genericLengthInteger" genericLength = (strictGenericLength :: [a] -> Integer);
+ #-}
+
+strictGenericLength :: (Num i) => [b] -> i
+strictGenericLength l = gl l 0
+ where
+ gl [] a = a
+ gl (_:xs) a = let a' = a + 1 in a' `seq` gl xs a'
+
-- | The 'genericTake' function is an overloaded version of 'take', which
-- accepts any 'Integral' value as the number of elements to take.
genericTake :: (Integral i) => i -> [a] -> [a]
--
1.9.1