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.
rev foo @ bar
would benefit from being writtenList.rev_append foo bar
, which will traversefoo
once instead of twice. – Holter