9 Jan
2002
9 Jan
'02
6:10 p.m.
Why, in the following program:
createFile = unsafePerformIO $ writeFile "test.xxx" ('1' : (take 10000000 (repeat '0')) ++ "1")
processFile = unsafePerformIO $ do f <- readFile "test.xxx" return (dropWhile (=='0') $ dropWhile (/='0') f)
does the amount of memory used by 'processFile' depend on the size of the file created? that is, if the take 10000000 is replaced by 100000000, the execution of processFile takes (around) ten times as much memory. it appears that it's storing all of f in memory even though all it really needs is the last character. how can i make this more lazy? (this was all done in ghc) - Hal