X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=topics%2Fweek12_list_and_tree_zippers.mdwn;h=89d83b69af691215a0be8cae74c868b84192e609;hb=935fb6c127006b69a492ef8e04cdb52a44e88169;hp=3f7ca7a648ff5599d08cfed0d618298c4f513eb2;hpb=1d20f8bccfa106e8bd611c366d94734b10750891;p=lambda.git diff --git a/topics/week12_list_and_tree_zippers.mdwn b/topics/week12_list_and_tree_zippers.mdwn index 3f7ca7a6..89d83b69 100644 --- a/topics/week12_list_and_tree_zippers.mdwn +++ b/topics/week12_list_and_tree_zippers.mdwn @@ -1,3 +1,5 @@ + + [[!toc]] ##List Zippers## @@ -266,50 +268,33 @@ probably not represent siblings with a list zipper, but with something more special-purpose and economical. With these functions, we can refocus on any part of the tree. -Here's a complete tour: +Let's abbreviate a tree zipper like this: + + [2;3], ([] [4] ([1], [], Root)) + + â¡ (Branch [Leaf 2; Leaf 3], + Context ([], [Leaf 4], Context ([Leaf 1], [], Root))) + +Then we can take a tour of the original tree like this:
-# let z1 = (t1, Root);; -val z1 : zipper = - (Branch [Leaf 1; Branch [Branch [Leaf 2; Leaf 3]; Leaf 4]], Root) -# let z2 = downleft z1;; -val z2 : zipper = - (Leaf 1, Context ([], [Branch [Branch [Leaf 2; Leaf 3]; Leaf 4]], Root)) -# let z3 = right z2;; -val z3 : zipper = - (Branch [Branch [Leaf 2; Leaf 3]; Leaf 4], Context ([Leaf 1], [], Root)) -# let z4 = downleft z3;; -val z4 : zipper = - (Branch [Leaf 2; Leaf 3], - Context ([], [Leaf 4], Context ([Leaf 1], [], Root))) -# let z5 = downleft z4;; -val z5 : zipper = - (Leaf 2, - Context ([], [Leaf 3], - Context ([], [Leaf 4], Context ([Leaf 1], [], Root)))) -# let z6 = right z5;; -val z6 : zipper = - (Leaf 3, - Context ([Leaf 2], [], - Context ([], [Leaf 4], Context ([Leaf 1], [], Root)))) -# let z7 = up z6;; -val z7 : zipper = - (Branch [Leaf 2; Leaf 3], - Context ([], [Leaf 4], Context ([Leaf 1], [], Root))) -# let z8 = right z7;; -val z8 : zipper = - (Leaf 4, - Context ([Branch [Leaf 2; Leaf 3]], [], Context ([Leaf 1], [], Root))) -# let z9 = up z8;; -val z9 : zipper = - (Branch [Branch [Leaf 2; Leaf 3]; Leaf 4], Context ([Leaf 1], [], Root)) -# let z10 = up z9;; -val z10 : zipper = - (Branch [Leaf 1; Branch [Branch [Leaf 2; Leaf 3]; Leaf 4]], Root) -# z10 = z1;; -- : bool = true -# z10 == z1;; -- : bool = false +_|__ +| | +1 | + _|__ + | | + | 4 + _|__ + | | + 2 3 + + [1;[[2;3];4]],Root = [1;[[2;3];4]],Root + downleft up +1, ([],[[2;3];4],Root) right [[2;3];4],([1],[],Root) [[2;3];4],([1],[],Root) + downleft up + [2;3],([],[4],([1],[],Root)) [2;3],([],[4],([1],[],Root)) right 4,([2;3],[],([1],[],Root)) + downleft up + 2, ([],[3],([],[4],([1],[],Root))) right 3, ([2],[],([],[4],([1],[],Root)))Here's more on zippers: