[Haskell-cafe] HaXml question

Tim Newsham newsham at lava.net
Fri Aug 18 01:47:27 EDT 2006

I thought this one would be easy but I'm starting to think its not.
I am playing with HaXml and I want to transform an XML tree into
another tree.  The transforms are simple enough, but the kicker
is that I want them to be "stateful."  In this example, the state
is a random number generator.  So the transformation depends on
the current node and the random number generator state.  I want
to transform every node in the tree.

My feeble attempt at this is given in:

What I see when I run it is that the value of "p" in the "tweak"
function is identical each time.  Indeed, it seems "g" itself
is the same each time "tweak" is invoked (I wrote a variant of
the program that used sequential integers instead of generators
to verify this).

So here's what I think is going on.  You can probably skip this
section because I am probably off base anyway...  I guess "keep"
is being applied to one node, and returning a list of 1 node,
and this is zipped with my infinite list of generators and as
a result I get the same generator each time.  If this is the case
I guess foldXml is not the right tool for this job.  Perhaps I
want a newly-written foldXml that works with LabelFilters rather
than CFilters?

Ok.. so what's really going on here.  Can I do what I want to do?
Whats the right tool to transform every node in the tree?  Is there
a more general approach to doing stateful transformations?

Thanks in advance for letting me waste your time.

P.S. any stylistic advice, or alternate approaches also welcome.
The objective here is to learn...

Tim Newsham

More information about the Haskell-Cafe mailing list