
20 Apr
2005
20 Apr
'05
5:22 a.m.
On 19 April 2005 15:37, Santoemma Enrico wrote:
I've always thought that compilers for functional languages were able to recognize tail recursion and to transform it into a loop. So, why this line eats all my machine's memory (and then runs out of stack space)?
sum [1..10000000] -- ten millions
Without optimisation, or in GHCi, you get the overloaded version of sum: sum :: (Num a) => [a] -> a the compiler therefore cannot assume that (+) is strict. If you compile with optimisation, you'll get sum specialised to Int or Integer, which will use the strict definition. Cheers, Simon
7335
Age (days ago)
7335
Last active (days ago)
0 comments
1 participants
participants (1)
-
Simon Marlow