
10 Apr
2006
10 Apr
'06
3:32 p.m.
On Mon, 10 Apr 2006, Chris Kuklewicz
If the goal is speed, then this definition is running over 10% faster with ghc -O2 on my powerbook for (sum $ map length $ inits [1..10000])
inits' = helper id where helper f [] = (f []):[] helper f (x:xs) = (f []):helper (f.(x:)) xs
This function looks like it's exactly equivalent to the H98 one, but I haven't checked the details. Furthermore, this definition made me think of a flaw in many of the others: they won't work for infinite lists. (Note that length ([1..] :: [Int]) = maxBound :: Int.) -- /NAD