Strict foldl

Ch. A. Herrmann herrmann@infosun.fmi.uni-passau.de
Thu, 6 Dec 2001 20:19:02 +0100


Hi Haskellers,

which compiler settings do I have to pass to ghc-5.02
in order to achieve that the strictness analyzer
recognizes strictness of (+) in foldl and computes
sum in constant space?

Prelude> sum [1..10000000]

had the following effect:

  PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME COMMAND
23542 herrmann  20   0  250M 130M 97500 R    66.3 52.4   0:21 ghc-5.02

Of course, one could define a strict foldl oneself:

> sfoldl f e [] = e
> sfoldl f e (x:xs) = (sfoldl f $! (f e x)) xs

(  > sfoldl (+) 0 [1..10000000] 
   returns 50000005000000 in about a minute interpreted 
   using 18MB of total space.)

But with the own definition one has to redefine many of the prelude functions.

Thanks in advance
--
 Christoph Herrmann