[Haskell-cafe] XmlSerializer.deserialize?

Udo Stenzel u.stenzel at web.de
Sun Jun 24 19:41:03 EDT 2007


Hugh Perkins wrote:
> Hi,
> 
> Trying to write a function to deserialize a haskell type from xml.
> 
> deserializeXml :: Data(a) => String -> a

That type signature describes a function that can deliver *anything*
(that is in class Data), whatever you ask from it.  From your
description (also the one in your other mail) it rather sounds as if you
want a function that delivers *something* (only restricted to be in
class Data), with you not asking for anything specific.  The correct
type would be something like:

data Any = forall a . Data a => Any a
deserializeXml :: String -> Any

(The syntax might be very wrong, I don't actually use this weird stuff.)
Now what would you do with the resulting 'Any'?  Pass it to a function
of course:

applyAny :: (forall a . Data a => a -> b) -> Any -> b
applyAny f (Any a) = f a

...and there aren't all that many functions that would fit the bill,
only generic ones.  If you do that, you wind up dragging in all the
machinery of Data.Generic just to implement what HaXml does with much
simpler technology.  I doubt that's what you actually want.

On the other hand, I might be misunderstanding.  In that case,
Data.Generics should have everything you need, in particular gunfold and
friends.


-Udo
-- 
"In the software business there are many enterprises for which it is not
clear that science can help them; that science should try is not clear
either."
	-- E. W. Dijkstra
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070625/d15105e6/attachment.bin


More information about the Haskell-Cafe mailing list