[Haskell-cafe] implementing a csv reader

Robert Dockins robdockins at fastmail.fm
Wed Aug 23 16:24:25 EDT 2006

On Aug 23, 2006, at 3:37 PM, Henk-Jan van Tuyl wrote:

> L.S.,
> Reading and writing a comma seperated datafile doesn't have to be  
> that complicated; the following is an easy way to read a CSV file  
> into a list of tuples and display the list on screen:

"For every complex problem, there is a solution which is simple,  
neat, and wrong."  -- HL Mencken

Although it seems straightforward at first, CSV suffers from text  
escaping complexities, just as does every other general purpose plain- 
text encoding.  Most notably, a newline embedded inside double quotes  
does not end a record.  These issues cause ugly corner cases if you  
aren't expecting them.  And that's just the issues with moving tables  
of strings around; if those fields have non-string interpretations  
(dates or numbers or what have you), things get really hairy.  To do  
the "right thing" probably requires perl-ish duck typing  :-p

See http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm for a semi- 
authoritative reference on CSV.  A related RFC is here: http:// 

Rob Dockins

Speak softly and drive a Sherman tank.
Laugh hard; it's a long way to the bank.
           -- TMBG

More information about the Haskell-Cafe mailing list