Strict foldl

Hal Daume III hdaume@ISI.EDU
Thu, 6 Dec 2001 15:43:08 -0800 (PST)


Hi,

> Is this what I think it is?  Do you benchmark the
> interpreter?  Interpreted code isn't optimised.  When I
> compile 
> 
>   main = print $ sum [1..10000000]
> 
> with -O2, it takes 13s on a 600MHz P3 and runs in 1.5MB of
> space.

Out of curiousity, why doesn't this get compiled down to

  main = print 50000005000000

?

That is, why doesn't the compiler carry out the calculation and then just
embed that in the compiled version?

I know that some C compilers do (at least somewhat) similar things when,
for example, you say:

  x = y * 4

it will rewrite this as

  x = y << 2

and even do more complicated stuff, like if you say

  x = y * 12

it will give

  x = 3 * (y << 2)

or whatnot.

can I expect this from ghc/nhc/etc?

 - hal