
Better still is McBride and Paterson's idiomatic traverse, which subsumes monadic gmap and a bit more (since some idioms - phantom idioms - aren't monads). The serialise/deserialise example is given there too. See Bruno's and my paper "The Essence of the Iterator Pattern". http://web.comlab.ox.ac.uk/jeremy.gibbons/publications/#iterator Jeremy On 27 Jun 2007, at 09:39, oleg@pobox.com wrote:
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)) []]
_______________________________________________ Generics mailing list Generics@haskell.org http://www.haskell.org/mailman/listinfo/generics
Jeremy.Gibbons@comlab.ox.ac.uk Oxford University Computing Laboratory, TEL: +44 1865 283508 Wolfson Building, Parks Road, FAX: +44 1865 283531 Oxford OX1 3QD, UK. URL: http://www.comlab.ox.ac.uk/oucl/people/jeremy.gibbons.html