inits

Nils Anders Danielsson nad at cs.chalmers.se
Mon Apr 10 15:32:37 EDT 2006


On Mon, 10 Apr 2006, Chris Kuklewicz <haskell at list.mightyreason.com> wrote:

> 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



More information about the Libraries mailing list