Haskell-beginners problem with memory consuption

Petter Egesund petter.egesund at kunnskapsforlaget.no
Wed Oct 1 16:18:51 EDT 2003

Hi, I have just started using Haskell, and it has been really fun so far.
But I have problems with memory usage when handling large files. What I do
is the following;

I load my file in one chunk, and does a lot of substitutes on the string -
this is quick eating all my memory and the computers start to get really

The problem is of course that the string is copied each time I do a
substitute, and I wonder if a more experienced haskeller has a better
solution to my problem.

I have myself considered these solutions, but they all seems non-elegant;

1. Use some IO extensions to fake a mutable variable - but solving a problem
like this with a solution which is meant for IO does not seem right?

2. Split the file in smaller parts could be a solution, but then I would
have to do a lot of preparsing to make sure I not spilt my file in the
middle of a pattern. Sounds to me like developing a lex-like system for such
a easy task is overkill?

3. I could maybe use some form of mutable arrays, but doing string regexps
on an array...?

4. ?

Any clues or opinions?


Petter Egesund

More information about the Haskell-Cafe mailing list