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

Lyndon Maydwell maydwell at gmail.com
Fri May 30 23:07:00 UTC 2014


I've never heard of a csv code-generation tool that works like this,
but it doesn't look like it would be too hard to hand-roll one, or do
you want to bypass code-generation?

 - Lyndon

On Sat, May 31, 2014 at 8:50 AM, Mark Fredrickson
<mark.m.fredrickson at gmail.com> wrote:
> 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
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>


More information about the Beginners mailing list