Dan: Sorry, I forgot to Reply to All. On 12/10/2007, Dan Weston <[EMAIL PROTECTED]> wrote: ... > We don't want to make an intermediate list of zeroes and append, since > that could be wasteful. Just keep adding a zero to the head of our list > until it gets big enough. Our list is not copied (i.e. it is shared with > the tail of the result) this way, saving making a copy during reverse.
It's actually much less efficient to create a big function that prepends a list of zeroes than just to create that list of zeroes and prepend it. You will be much better of just using (replicate n e ++) than (applyNtimes (e:) n). Contrived benchmark: Prelude> sum . map length $ [replicate i 0 ++ [1..10] | i <- [1..2000]] 2021000 (0.19 secs, 114581032 bytes) Prelude> sum . map length $ [applyNtimes (0:) i [1..10] | i <- [1..2000]] 2021000 (2.51 secs, 242780204 bytes) _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
