Question

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.

Was it helpful?

Solution

The zipper here is for the following tree datatype:

type tree =
   Item of item
 | Section of tree list;;

And the path datatype from the paper is this:

type path =
   Top
 | Node of tree list * path * tree list;;

The Node contains 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 t at the right position in between left and right. As the children to the left are stored in reverse order, we have to reverse them first.

OTHER TIPS

the author concatenates the current nodes and its siblings. But that's not a parent node, just the children of the parent node

With the paper definition cited by kosmikus, a non-leaf node Section is defined by nothing other than its children. If you have added additional information, you must add it to the definition of the zipper.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top