[Template-haskell] is this (.csv) a good task for template-haskell?
Lloyd Allison
Lloyd.Allison at infotech.monash.edu.au
Mon Jul 11 07:40:34 EDT 2005
I'd like to write some Haskell programs to manipulate
comma-separated variable, .csv, files from a spreadsheet.
The obvious way to start which, for perverse(?) reasons,
I do not want to follow is to create a union type e.g.
data CSVelement = I int | S string | ...
or similar.
All the elements of a given column will be of the same type
e.g. bool, int, float,
string, or
a-selection-of-names (e.g. {Lab, Con, LibDem}).
(and some columns with missing values).
e.g. "Homer",42,67.8,Lab
"Paris",,5.5,Con
...
I'd like to write some code that
1. takes a quick look at the file,
counts the columns,
works out the type of each column
(including creating data T1 = Lab|Con|LibDem,
and using `Maybe' for missing values),
2. creates a tuple-type for a row,
e.g. (String, Maybe Int, Float, T1), and
adds that type to Reads, Show (and some other stuff), and
3. then gets on with processing the data.
Is template-Haskell a good choice for this task and,
if so, what is the quickest way to get started?
(Or has it been done?)
-Lloyd
--
Lloyd ALLISON, CSSE, Monash University, Victoria, Australia 3800.
web: http://www.csse.monash.edu.au/~lloyd/ tel: +61 3 9905 5205
More information about the template-haskell
mailing list