(Usual apologies if this has been noted/solved since 2.05.)
The following program (which sums [1..n] by brute force):
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
import System(getArgs)
data Test = Test !Int
f :: Test -> Int -> Test
f (Test n) i = Test (n+i)
g :: Test -> Int
g (Test n) = n
sfoldl :: Eval a => (a -> b -> a) -> a -> [b] -> a
sfoldl f z [] = z
sfoldl f z (x:xs) = sfoldl f fzx (fzx `seq` xs)
where fzx = f z x
main = do argv <- getArgs
print (g (sfoldl f (Test 0) [1..(read (argv!!0))]))
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
blows the heap up when compiled with GHC, but not with HBC or Hugs.
The strict version of foldl will apply seq to (f (Test n) i) which
should force it to (Test (n+i)) and the (n+i) should be evaluated
because of the strictness annotation. Thus the program should run in
constant space (indeed with a heap of just 32Kb, compiled with HBC, it
can evaluate the sum of [1..50000]).
I'm using GHC 2.05.
Graeme.