<div dir="ltr">I&#39;m no lens authority by any means, but indeed, it looks like something like Cursor / Axis could be done with the lens zipper.<br><br><a href="https://github.com/snoyberg/xml/blob/0367af336e86d723bd9c9fbb49db0f86d1f989e6/xml-enumerator/Text/XML/Cursor/Generic.hs#L38">https://github.com/snoyberg/xml/blob/0367af336e86d723bd9c9fbb49db0f86d1f989e6/xml-enumerator/Text/XML/Cursor/Generic.hs#L38</a><br>

<br>This cursor datatype is very much like the (:&gt;) zipper type (I&#39;m linking to old code, because that&#39;s when I understood it - the newer stuff is semantically the same, but more efficient, more confusing, and less directly relatable):<br>

<br><a href="https://github.com/ekmett/lens/blob/f8dfe3fd444648f61b8594cd672c25e70c8a30ff/src/Control/Lens/Internal/Zipper.hs#L317">https://github.com/ekmett/lens/blob/f8dfe3fd444648f61b8594cd672c25e70c8a30ff/src/Control/Lens/Internal/Zipper.hs#L317</a><br>

<br>Which is built out of the following two datatypes:<br><br>1) parent (and the way to rebuild the tree on the way back up) is provided by this datatype:<br><br><a href="https://github.com/ekmett/lens/blob/f8dfe3fd444648f61b8594cd672c25e70c8a30ff/src/Control/Lens/Internal/Zipper.hs#L74">https://github.com/ekmett/lens/blob/f8dfe3fd444648f61b8594cd672c25e70c8a30ff/src/Control/Lens/Internal/Zipper.hs#L74</a><br>

<br>2) precedingSibling / followingSibling / node is provided by this datatype (which is pretty much the familiar list zipper!):<br><br><a href="https://github.com/ekmett/lens/blob/f8dfe3fd444648f61b8594cd672c25e70c8a30ff/src/Control/Lens/Internal/Zipper.hs#L317">https://github.com/ekmett/lens/blob/f8dfe3fd444648f61b8594cd672c25e70c8a30ff/src/Control/Lens/Internal/Zipper.hs#L317</a><br>

<br><br>One way that this would be powerful is that some of the Axis constructors could return a zipper.  In particular, all of the axis yielding functions except the following would be supported:<br><br>parent, precedingSibling, followingSibling, ancestor, descendent, orSelf, check<br>

<br>This is because zippers can be used for modification, which doesn&#39;t work out very well when you can navigate to something outside of your focii&#39;s children.  If we have a new datatype, that represents a node&#39;s payload, then we could conceivably represent all of the axis yielding operations except for parent / ancestor.  However, those operations would be navigations to payloads - further xml-hierarchy level navigation would be impossible because you&#39;d no longer have references to children.  (further navigation into payloads on the other hand, would still be possible)<br>

<br>So, that&#39;s just my thoughts after looking at it a bit - I hope it&#39;s comprehensible / helpful!  An XML zipper would be pretty awesome.<br><br>-Michael</div><div class="gmail_extra"><br><br><div class="gmail_quote">

On Sun, Feb 10, 2013 at 8:34 PM, Michael Snoyman <span dir="ltr">&lt;<a href="mailto:michael@snoyman.com" target="_blank">michael@snoyman.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote"><div class="im">On Sun, Feb 10, 2013 at 8:51 PM, grant <span dir="ltr">&lt;<a href="mailto:thelff@hotmail.com" target="_blank">thelff@hotmail.com</a>&gt;</span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Michael Snoyman &lt;michael &lt;at&gt; <a href="http://snoyman.com" target="_blank">snoyman.com</a>&gt; writes:<br>




<br>
&gt;<br>
<br>
</div>Hi Michael,<br>
<br>
Just one last thought. Does it make any sense that xml-conduit could be<br>
rewritten as a lens instead of a cursor? Or leverage the lens package somehow?<br>
<div><div><br></div></div></blockquote><div><br></div></div><div>That&#39;s a really interesting idea, I&#39;d never thought about it before. It&#39;s definitely something worth playing around with. However, I think in this case the Cursor is providing a totally different piece of functionality than what lenses would do. The Cursor is really working as a Zipper, allowing you to walk the node tree and do queries about preceding and following siblings and ancestors.</div>



<div><br></div><div>Now given that every time I&#39;m on #haskell someone mentions zippers in the context of lens, maybe lens *would* solve this use case as well, but I&#39;m still a lens novice (if that), so I can&#39;t really speak on the matter. Maybe someone with more lens experience could provide some insight.</div>



<div><br></div><div>Either way, some kind of lens add-on sounds really useful.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Michael </div></font></span></div></div></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>