
Once more I forgot to send my messages to the haskell cafe list. All the
rest of the list which I´m suscribed to, send the mail replies to the list
automatically, but this doesn´t. Please, can this be changed?.
---------- Forwarded message ----------
From: Alberto G. Corona
Prelude> let strictplus x y= let z=x +y in z `seq` z; sum1= foldr
*** Exception: stack overflow I suppose that strictplus is strict, so the garbage collector would free
strictplus 0 in sum1[0..1000000] the consumed part of the list.
Then, why the stack overflow? 2009/6/13 Deniz Dogan
2009/6/13 Jochem Berndsen
: Keith Sheppard wrote:
Is there any reason that sum isn't strict? I can't think of any case where that is a good thing.
Prelude> sum [0 .. 1000000] *** Exception: stack overflow
It is useful if the (+) is nonstrict; although I cannot think of any useful mathematical structure where (+) would be nonstrict.
I remember needing a non-strict sum at least once, but I do not remember the exact application. But imagine having a (very) long list of numbers and you want to do A if the sum exceeds a small number, otherwise B.
if sum [0..100000] > 10 then A else B
However, this idea didn't work, because of strictness.
-- Deniz Dogan _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe