[Hs-Generics] xml deserialization using generics?
oleg at pobox.com
oleg at pobox.com
Wed Jun 27 04:39:12 EDT 2007
Hugh Perkins wrote:
> Cant decide whether this list is appropriate for questions related to
> generics usage, or only to generics design?
I think your question is quite appropriate -- actually, it is a good
question. It asks essentially for a monadic gmap, which seems quite
important. This operation is also the `inverse' of one of our
comparison tests: listify. The latter collects values from the leaves
of a data type in a list. That list is a `state' of a value, so to
speak. The state can be transported over the network, and, on the
other end, can be infused into a prototype object (assuming it has the
same structure).
The monadic gmap subsumes two traversals: generic map and
reduction. So, your question looks even better.
I wonder if we should add monadic gmap to our test suite?
I have just committed the monadic gmap implementation and the test for
one generic library, the one I'm more familiar with. The test is in
the file
http://darcs.haskell.org/generics/comparison/SmashA/Deserialize.hs
We start with the data type of a company
C [D "Research" (E (P "Laemmel" "Amsterdam") (S 8000.0))
[PU (E (P "Joost" "Amsterdam") (S 1000.0)),
PU (E (P "Marlow" "Cambridge") (S 2000.0))],
D "Strategy" (E (P "Blair" "London") (S 100000.0)) []]
(see http://darcs.haskell.org/generics/comparison/CompanyDatatypes.hs)
We can serialize it:
test1 = serialize genCom
obtaining a list
["Research","Laemmel","Amsterdam","8000.0","Joost","Amsterdam",
"1000.0","Marlow","Cambridge","2000.0","Strategy","Blair",
"London","100000.0"]
OTH, we can take the list
retro = ["Metaphysics",
"Kant","Koeningsberg","800.0",
"Hume","Edinburgh","100.0",
"Marlowe","Cambridge","200.0",
"Ruling","Thatcher","London","50000.0"]
and use it to `upgrade' the company genCom:
test2 = deserialize genCom retro
giving us
*Deserialize> test2
C [D "Metaphysics" (E (P "Kant" "Koeningsberg") (S 800.0))
[PU (E (P "Hume" "Edinburgh") (S 100.0)),
PU (E (P "Marlowe" "Cambridge") (S 200.0))],
D "Ruling" (E (P "Thatcher" "London") (S 50000.0)) []]
More information about the Generics
mailing list