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
_______________________________________________
Glasgow-haskell-users mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to