I’m reading Huet Zipper, I cannot understand the go_up method:
let go_up (Loc(t,p)) = match p with
Top -> failwith "up of top"
| Node(left,up,right) -> Loc(Section((rev left) @ (t::right)),up);;
The full source of other types definitions can be found in the linked paper, if you understand Zipper, I think that doesn’t matter to answer my question.
From what I know about Zipper, a Location contains the current node and its Path or the so called Context.
The Path has everything other than the current node and its subnodes, or some people called it a one-hole-context.
Well, moving the focus up, means the parent node of the current node will become the new current node. But here, the author concatenates the current nodes and its siblings.
But that’s not a parent node, just the children of the parent node.
I am stuck at here when implementing my own moveUp method in Scala, and failed to correctly represent the parent node of the current node.
The zipper here is for the following tree datatype:
And the path datatype from the paper is this:
The
Nodecontains three components. The children of the parent node that are to the left of the hole (left), the path further up (up), and the children of the parent node that are to the right of the hole (right).When moving up, in order to produce the actual parent node, we have to plug in the old tree
tat the right position in betweenleftandright. As the children to the left are stored in reverse order, we have to reverse them first.