[Haskell-cafe] Question about zippers on trees

Dominik Schrempf dominik.schrempf at gmail.com
Wed Jul 22 11:40:39 UTC 2020


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



More information about the Haskell-Cafe mailing list