[Haskell-cafe] Processing of large files

Alexander N. Kogan alexander at kogan.nnov.ru
Mon Nov 1 12:52:42 EST 2004


I'm newbie and I don't understand how to process large files in haskell with 
constant memory requirements. For example, to count numbers of different 
words in text file I wrote following program:
-- start
import System.Environment

merge [] x = [(x,1)]
merge (e@(a,b):xs) x | x == a  = (a,b+1):xs
                                     | otherwise  = e : merge xs x

procFile =
    putStrLn       .
    show       .
    foldl merge []      .

main = do
    args <- getArgs
    readFile (head args) >>= procFile
-- end

How should I modify it to make it useful on large file?
It eats too much memory...

Alexander Kogan
Auto Wave Processes Group
Institute of Applied Physics RAS

More information about the Haskell-Cafe mailing list