<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>Shouldn’t that be:</div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> _before :: [TreePos a]</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div>etc.?</div><div><br></div><div>Jeff</div><div><br>On Jul 22, 2020, at 4:54 AM, Andrew Martin <<a href="mailto:andrew.thaddeus@gmail.com">andrew.thaddeus@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">From containers, Tree is defined as:<br><br> data Tree a = Node<br> { label :: a<br> , children :: [Tree a]<br> }<br><br>(I've renamed the record labels.) What is a zipper into such a tree? I think<br>that the [rosezipper](<a href="https://hackage.haskell.org/package/rosezipper-0.2/docs/Data-Tree-Zipper.html">https://hackage.haskell.org/package/rosezipper-0.2/docs/Data-Tree-Zipper.html</a>)<br>library gives a good definition. I'll specialized it to rose trees:<br><br> data TreePos a = Loc<br> { _content :: Tree a -- ^ The currently selected tree.<br> , _before :: [Tree a] -- ^ Forest to the left<br> , _after :: [Tree a] -- ^ Forest to the right<br> , _parents :: [([Tree a], a, [Tree a])] -- ^ Finger to the selected tree<br> }<br><br>I think that does it. I wouldn't recommend using a library for this kind<br>though. Just define `TreePos` in your code and then write the functions<br>that you happen to need.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 22, 2020 at 7:41 AM Dominik Schrempf <<a href="mailto:dominik.schrempf@gmail.com">dominik.schrempf@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello Cafe!<br>
<br>
I am trying to modify a large 'Data.Tree.Tree'. I managed to modify node labels<br>
with specific indices in the form of @[Int]@ as they are defined in, for<br>
example, 'Control.Lens.At.Ixed' or 'Lens.Micro.GHC'.<br>
<br>
However, I also need to<br>
1. modify the node label using information from nearby nodes (e.g., the<br>
children);<br>
2. modify the tree structure itself; for example, I may want to change the<br>
sub-forest.<br>
<br>
Basically, I need a lens that focuses not on the node label, but on the node<br>
itself. I perceived that this is more difficult.<br>
<br>
I tried to use 'Control.Zipper'. I can use zippers to achieve point 1, albeit in<br>
a complicated way: (1) I need to go downwards to focus the specific node; (2) I<br>
need to traverse the children to collect data and save the data somewhere (how?<br>
in let bindings?); (3) I then go back upwards and change the node label using<br>
the collected data. Even so, I do not really manage to change the actual<br>
structure of the tree. I also briefly had a look at plates, but do not manage to<br>
use them in a proper way, maybe because the depth of my structures may be<br>
several hundred levels.<br>
<br>
Did you encounter similar problems in the past or could you point me to<br>
resources discussing these issues?<br>
<br>
Thank you!<br>
Dominik<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature">-Andrew Thaddeus Martin</div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Haskell-Cafe mailing list</span><br><span>To (un)subscribe, modify options or view archives go to:</span><br><span><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a></span><br><span>Only members subscribed via the mailman list are allowed to post.</span></div></blockquote></body></html>