[Haskell-beginners] A question on seq
Felipe Lessa
felipe.lessa at gmail.com
Tue Sep 14 18:40:47 EDT 2010
On Tue, Sep 14, 2010 at 6:26 PM, Klaus Gy <klausgy at gmail.com> wrote:
> What should be the difference?
There's at least one big difference. 'secondSum' keeps the whole list
in memory, because it only starts summing after it got to the tail of
the list. This causes bad behaviour when the list doesn't need to be
kept around:
*Main> secondSum (replicate 1000000 0)
0
(32.34 secs, 503758400 bytes)
*Main> firstSum 0 (replicate 1000000 0)
0
(0.98 secs, 243311272 bytes)
Cheers!
--
Felipe.
More information about the Beginners
mailing list