Ian Holyer wrote:
> [...]
> As far as we can see, the problem boils down to a classic known problem: [...]
>
> let (x,y) = e in ...
>
> [...]
> I know of two solutions for handling it. One is for the compiler to generate
> special code for "let (x,y) = e in ..." where the code for evaluating e also
> updates x and y appropriately.
Just for reference: This solution corresponds to
Jan Sparud: Fixing Some Space Leaks without a Garbage Collector (FPCA-93)
ftp://ftp.cs.chalmers.se/pub/cs-reports/papers/sparud/spaceleak-fix.ps.gz
> The other is for the run time system to look for opportunities for eliminating
> indirection-like constructs such as "y = snd (e1,e2)" either in the garbage
> collector or in a low-priority background process.
And this one to
Philip Wadler "Fixing a space leak with a garbage collector"
Software Practice & Experience , 17(9):595-608, September 1987.
ftp://ftp.dcs.gla.ac.uk/pub/glasgow-fp/authors/Philip_Wadler/leak.dvi
AFAIK, Hugs uses none of these. Simple test (adapted from Wadler's paper):
------------------------------------------------------------------------
chop :: String -> (String,String)
chop [] = ([],[])
chop ('\n':xs) = ([],xs)
chop (x :xs) = let (f,s) = chop xs in (x:f, s)
surprise :: String -> String
surprise xs = let (f,s) = chop xs in f ++ "\nsurprise\n" ++ s
main :: IO ()
main = readFile "test.txt" >>= putStr . surprise
------------------------------------------------------------------------
Using this on a file test.txt with a very long first line (e.g. 100000
characters), Hugs runs out of heap space. Using the heap profiling option
-d, one can watch the heap increase in a linear manner.
GHC's behaviour is even worse: In addition to a large heap, the compiled
program needs *lots* of stack space, too. Comments (or excuses :-) from
Glasgow?
Space leaks like this are lurking in a lot of places in the standard
prelude, so it's quite funny that Hugs/GHC don't address this problem,
although solutions are known.
What's the behaviour of NHC/HBC in these cases?
--
Sven Panne Tel.: +49/89/2178-2235
LMU, Institut fuer Informatik FAX : +49/89/2178-2211
LFE Programmier- und Modellierungssprachen Oettingenstr. 67
mailto:[EMAIL PROTECTED] D-80538 Muenchen
http://www.pms.informatik.uni-muenchen.de/mitarbeiter/panne