The answer is sometimes (only if you use an optimize flag): keith@sugarglider:~/temp/> cat sumtest.hs main = putStrLn . show . sum $ [0 .. 1000000] keith@sugarglider:~/temp/> ghc --make sumtest.hs [1 of 1] Compiling Main ( sumtest.hs, sumtest.o ) Linking sumtest ... keith@sugarglider:~/temp/> ./sumtest Stack space overflow: current size 8388608 bytes. Use `+RTS -Ksize' to increase it. keith@sugarglider:~/temp/> rm sumtest.hi sumtest.o sumtest keith@sugarglider:~/temp/> ghc --make -O2 sumtest.hs [1 of 1] Compiling Main ( sumtest.hs, sumtest.o ) Linking sumtest ... keith@sugarglider:~/temp/> ./sumtest 500000500000 keith@sugarglider:~/temp/> ghc --version The Glorious Glasgow Haskell Compilation System, version 6.10.1 But since hackage warns against using these flags when you upload packages I would think that most libraries would not be using a strict version of sum. On Mon, Jun 15, 2009 at 11:14 AM, Don Stewart<dons@galois.com> wrote:
keithshep:
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 strict when subject to strictness analysis (try compiling it).
-- Don
-- keithsheppard.name