[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  
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  
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.


   /\    / |       arthurvl at cs.uu.nl       | 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  

More information about the Haskell mailing list