[Haskell-beginners] Static records (CSV tables as modules)

Mark Fredrickson mark.m.fredrickson at gmail.com
Fri May 30 22:50:21 UTC 2014


Hello,

I writing a program that operates on some static data, currently saved in
CSV files. Right now I parse the files at run time and then generate
hashmap tables to connect the different data.

Since I'm only ever operating on static data, I'm wondering if I can
generate module files that capture the records as a sum type. To access the
fields of the records, I could then imagine functions that exhaustively map
the constructors to the data.

Do any tools to generate .hs files from CSV or other formats exist? Insofar
as this question has been asked before, the recommendation is "use Template
Haskell", which makes sense, but is a less complete solution than I'm
hoping for.

Here's example of what what would be generated in literal Haskell source:

-- input.csv
name, age, someValue
"abc", 1, 3.0
"xyz3", 99, -5.9

-- Input.hs
module Input where

data Row = R1 | R2

name :: Row -> String
name R1 = "abc"
name R2 = "xyz3"

age :: Row -> Integer
age R1 = 1
age R2 = 99

-- likewise for the function someValue

Thanks,
-M
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140530/ba5d9392/attachment.html>


More information about the Beginners mailing list