[Haskell-cafe] Question about zippers on trees

Andreas Källberg anka.213 at gmail.com
Wed Jul 22 12:59:34 UTC 2020


Nice timing, I was just reading Conal Elliott’s take on zippers [1][2] when you sent this question.

It is interesting because it produces a concrete representation of the zippers via derivatives, like the manually constructed zippers, while still being completely generic*.
I wonder if it is possible to combine the approach with lenses to get the same convenience while still being more concrete and flexible.

Regards,
Andreas

[1]: http://conal.net/blog/posts/another-angle-on-zippers <http://conal.net/blog/posts/another-angle-on-zippers>
[2]: http://hackage.haskell.org/package/functor-combo-0.3.6/docs/FunctorCombo-ZipperFix.html <http://hackage.haskell.org/package/functor-combo-0.3.6/docs/FunctorCombo-ZipperFix.html>

* The library is sadly not implemented in terms of `GHC.Generics`, even though it uses the same combinators, since it predated it.

> 22 Jul 2020 kl. 13:40 skrev Dominik Schrempf <dominik.schrempf at gmail.com>:
> 
> Hello Cafe!
> 
> I am trying to modify a large 'Data.Tree.Tree'. I managed to modify node labels
> with specific indices in the form of @[Int]@ as they are defined in, for
> example, 'Control.Lens.At.Ixed' or 'Lens.Micro.GHC'.
> 
> However, I also need to
> 1. modify the node label using information from nearby nodes (e.g., the
>   children);
> 2. modify the tree structure itself; for example, I may want to change the
>   sub-forest.
> 
> Basically, I need a lens that focuses not on the node label, but on the node
> itself. I perceived that this is more difficult.
> 
> I tried to use 'Control.Zipper'. I can use zippers to achieve point 1, albeit in
> a complicated way: (1) I need to go downwards to focus the specific node; (2) I
> need to traverse the children to collect data and save the data somewhere (how?
> in let bindings?); (3) I then go back upwards and change the node label using
> the collected data. Even so, I do not really manage to change the actual
> structure of the tree. I also briefly had a look at plates, but do not manage to
> use them in a proper way, maybe because the depth of my structures may be
> several hundred levels.
> 
> Did you encounter similar problems in the past or could you point me to
> resources discussing these issues?
> 
> Thank you!
> Dominik
> 
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20200722/f9ffd6f4/attachment.html>


More information about the Haskell-Cafe mailing list