[Haskell-cafe] advice on a parsing function
manlio_perillo at libero.it
Wed Mar 11 11:59:21 EDT 2009
I'm still working on the Netflix Prize; now I have managed to implement
a parsing function for the qualifying data set (or quiz set).
The quiz set is in the format:
Where 1, 2, 3 are movie ids, and the others are user ids.
The parsing program is at:
The program reads the file using lazy IO.
One of the feature I want is, for the quiz function, to be a *good
I'm quite satisfied with the result (this is the first "complex" parsing
function I have written in Haskell), and I have also managed to avoid
the use of an accumulator.
However I'm interested to know it there is a more efficient solution.
The qualifying.txt file is 51MB, 2834601 lines.
On my laptop, the function performance are:
CPU usage is about 3%,
system load is about 0.20,
memory usage is 4956 KB.
What I'm worried about is:
quiz' ((id, ":") : l) = (id, quiz'' l) : quiz' l
quiz' ((id, _) : l) = quiz' l
the problem here is that the same elements in the list are processed
I have written alternate versions.
The first using foldl
(that, however, builds the entire data structure in memory, and in
The latter using foldr
(that, however, is incorrect and I'm unable to fix).
The performances of the foldr version are very similar to the
performances of the first implementation (it make use, however, of 3704
KB, and it is about 3 seconds faster).
the expected result for the sample quiz set I have posted is:
The foldl version produces:
The foldr version produces:
Thanks Manlio Perillo
More information about the Haskell-Cafe