In many cases it would be useful to be able to set/get a record field via its name as a string (for instance, converting records to/from command line arguments, HTTP headers, SQL query results, or store widgets in a GUI tree in an easy to use record, etc). The functions could have the types
setField::String->Val->Record->Record
getField::String->Record->Val
getFieldNames::Record->[String]
where Val could be something that could convert to other types (string, glib GValue, or even the Convertables I described here)
I've started writing a library that does this, with plans contribute it to the community (it will need some GHC extensions, probably including TemplateHaskell)....
My question- Does something like this already exist? Is there a better way to populate Records from external name/value pairs? I've looked all over and can't find it. (lenses are related, but don't use the string name).
I think this would be useful, but don't want to reinvent the wheel.
Generic
. – bheklilrMap
? It's reasonable to reify to and fromRecord
and some record type (see aeson for example) but the record type itself can be dumb. – Daniel Gratzer