Why this happens?
Simon Marlow
simonmar at microsoft.com
Wed Apr 20 05:22:38 EDT 2005
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
More information about the Glasgow-haskell-users
mailing list