L.S.,

lately I've been playing with Data.Generics and records. I would like
to write a generic method to output to e.g. CSV files. Given MissingH.CVS
that problem reduces to a generic method to take lists of records to
lists of lists with shown record fields, with as first element a list of the
field names. That is, something quite like:

> totable :: [RecordType] -> [[String]]
> totable rs = fields (head rs) ++ map showrecord rs
> where fields a = constrFields . head . dataTypeConstrs . dataTypeOf $ a
>        showrecord = gmapQ (show . toConstr)

However, there are no guarantees whatsoever that the order of the fieldnames
returned by constrFields corresponds to the order in which gmapQ returns
the results for the children (that is the fields, in this case) of the records.

Furthermore, I see no way of forcing such an order otherwise, other than
writing boilerplate myself.

So, is there something I just haven't seen in the lib yet, is something
missing, or is just the documentation inconclusive and does the library
behave as I want it to?

Doei, Arthur.

--

/\ / | [EMAIL PROTECTED] | Work like you don't need the money /__\ / | A friend is someone with whom | Love like you have never been hurt / \/__ | you can dare to be yourself | Dance like there's nobody watching



_______________________________________________
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to