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