[Haskell] Parsing Typed Data from a String

Simon D. Foster u1sf at dcs.shef.ac.uk
Sat Mar 6 21:05:41 EST 2004

I am currently trying to implement a method of allowing arbitrary record
syntax data-types to be converted to and from an XML representation of
them using the Read and Show class; 

i.e. simply derive either Show and then parse the given String to
extract the name/value pairs which can then be converted to XML, or
using the XML generate a representation of the data entity (e.g.
"Person{name=\"Fred Smith\", age=47}") and read this back into an actual

However I have one small problem; the order of the incoming parameters
of the XML data-type representations is not guaranteed, but according to
Haskell 98 report;

"If the constructor is defined using record syntax...the fields must be
given in the same order as the original declaration."

So my question is, is there any method in GHC which allows you to
extract the order of the constructors in a type or to parse a
type-representation in such a way that the order of the records doesn't
matter (I am looking for ease/simplicity of use)?

Or do I just tell them to put the records in alphabetical order?


(Please CC replies to me).
Simon D. Foster <u1sf at dcs.shef.ac.uk>
Sheffield University

More information about the Haskell mailing list