[Haskell] SYB Documentation is inconclusive.
Arthur van Leeuwen
arthurvl at cs.uu.nl
Thu Nov 23 03:09:14 EST 2006
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
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
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
returned by constrFields corresponds to the order in which gmapQ returns
the results for the children (that is the fields, in this case) of
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?
/\ / | arthurvl at cs.uu.nl | Work like you don't need
/__\ / | A friend is someone with whom | Love like you have never
/ \/__ | you can dare to be yourself | Dance like there's nobody
More information about the Haskell