
24 Sep
2007
24 Sep
'07
5:01 p.m.
From the wiki: If you write it, you force Haskell to create all list nodes. ...
Alright. Now, lets look at the definition again:
length [] = 0 length (x:xs) = 1 + length xs
We see that the value of *x* isnt needed at all. So, why does GHC allocate so much memory creating all those *x*s? because, if we have: length [1..] = 1 + length [2...] = 1 + 1 + length [3...] This should go on, into an infinite loop. GHC doesnt need to create all nodes! The wiki also claims that *x* isnt evaluated. So, why allocate space for it when its not evaluated?