ghc-4.02  treats  sum  strangely.
In the below program,  sum xs  needs small, constant size stack,
sm xs  needs stack proportional to  length xs.
And  sm  is the implementation of  sum  shown in  src/.../PrelList.lhs
I apply  ghc -c -O.
What keys are needed to code  sum  like it is in this
ghc-4.02-linux-i386-unknown  binary?

Generally, how to make the compiler to save stack in the simplest
functions, like  sum,  specialized to Integer?
(apart of strictness annotations).

------------------
Sergey Mechveliani
[EMAIL PROTECTED]



-------------------------------------
sm = foldl (+) 0                  
{-# SPECIALISE sm :: [Int] -> Int #-}

main = let  xs = [1..789000] :: [Int]
            s1 = sum xs
            s2 = sm  xs
       in   putStr (shows s2 "\n")
                         







Reply via email to