fast IO in ghc
Wed, 3 Apr 2002 09:17:33 -0500
> I tend to deal a lot with very very large data files in Haskell and my
> current approach to dealing with getting data out of one program an into
> another is writing it to a file using 'show' and then reading it in using
> 'read'. Unfortunately, this is very slow and produces very large files
> which are very slow to read and write.
Be careful with your choice of Read and Show instances.
Standard reading of lists is ``strict in the closing bracket'',
so the first element is only returned after the end of the list
has been read.
I tend to define my own instances, using a fairly standard set
of parser combinators working on the ReadS type ---
this speeds up things considerably (and runs in less memory).
This can, of course, also be used to get file size down,
but in my circumstances this was not a major problem
(rarely had files of more than a few tens of megabytes),
and human-readability was useful to have.