In Data.Tree.Zipper the zipper data type for a rose tree is
data TreePos t a = Loc
{ _content :: t a -- ^ The currently selected tree.
, _before :: Forest a
, _after :: Forest a
, _parents :: [(Forest a, a, Forest a)]
} deriving (Read,Show,Eq)
Now it seems to me that the information in _after and _before is redundant as it should show up in the _parents field as well. (The siblings of a node are the children of its parents.)
Why is this? Out of convenience?
There is no redundant information. The
_parents
field contain the left and right siblings on the path from the focused tree to the root, but not the direct siblings.Let's look at a concrete example:
This tree can be represented as follows:
Now let's descend to the subtree with label
6
(I'm usingfromJust
here as an exception because I know exactly what tree we're dealing with):Now let's inspect the resulting location:
You can see that:
_contents
contains the selected subtree at label6
as expected,_before
contains the direct siblings to the left (in reverse order),_after
contains the direct siblings to the right,_parents
is a list containing two entries, because there are two levels above the selected tree, so it describes the path from the selected subtree to the top. The first entry says that we descended through label2
which has no left siblings and two right siblings. The second entry says that the root has label1
.