Sometimes it takes a while, but we get there eventually...

Graeme Moss <[EMAIL PROTECTED]> writes:

> (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.

This is a space leak related to the overloading on sfoldl in
conjunction with polymorphic recursion.  The patch is too big to post
here, but will be in the next release.

Workaround: specialise sfoldl, or comment-out the type signature.

Cheers,
        Simon

-- 
Simon Marlow                                             [EMAIL PROTECTED]
University of Glasgow                       http://www.dcs.gla.ac.uk/~simonm/
finger for PGP public key

Reply via email to