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
_parentsfield 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 usingfromJusthere as an exception because I know exactly what tree we're dealing with):Now let's inspect the resulting location:
You can see that:
_contentscontains the selected subtree at label6as expected,_beforecontains the direct siblings to the left (in reverse order),_aftercontains the direct siblings to the right,_parentsis 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 label2which has no left siblings and two right siblings. The second entry says that the root has label1.