From: Chris Date: Mon, 27 Apr 2015 00:10:09 +0000 (-0400) Subject: edits X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=commitdiff_plain;h=509e4a7f1a5cb60c7ca2444b8f4610d4f124e646;ds=sidebyside edits --- 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: