[Haskell-beginners] [Haskell-Beginners] Laziness & referential transparency

Tim Baumgartner baumgartner.tim at googlemail.com
Sat Jan 29 15:16:41 CET 2011


Hi everybody,

after reading a post by Don Stewart on
http://cgi.cse.unsw.edu.au/~dons/blog/2008/05/16#fast, I was not really
satisfied with the necessity to rewrite

mean xs = sum xs / fromIntegral (length xs)

to an explicitly recursive function. I investigated a bit further and got
really confused after the following GHCi session:

Prelude> length [1..10^8] + length [1..10^8]
200000000
Prelude> let xs = [1..10^8]
Prelude> length xs + length xs
<interactive>: out of memory

Can someone explain this and give a simple, reasonable rule by which I can
predict such things in the future? Isn't it a pitfall?

Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110129/2535a6ff/attachment.htm>


More information about the Beginners mailing list