week11 tweaks
authorJim Pryor <profjim@jimpryor.net>
Tue, 30 Nov 2010 16:25:48 +0000 (11:25 -0500)
committerJim Pryor <profjim@jimpryor.net>
Tue, 30 Nov 2010 16:25:48 +0000 (11:25 -0500)
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
assignment8.mdwn
week11.mdwn

index 495ef2f..59e0090 100644 (file)
@@ -2,9 +2,10 @@
 
                type 'a tree = Leaf of 'a | Node of ('a tree * 'a tree)
 
 
                type 'a tree = Leaf of 'a | Node of ('a tree * 'a tree)
 
-               type 'a starred_tree = Root | Starring_Left of 'a starred_pair | Starring_Right of 'a starred_pair
-               and 'a starred_pair = { parent : 'a starred_tree; sibling: 'a tree }
-               and 'a zipper = { tree : 'a starred_tree; filler: 'a tree };;
+               type 'a starred_level = Root | Starring_Left of 'a starred_nonroot | Starring_Right of 'a starred_nonroot
+               and 'a starred_nonroot = { parent : 'a starred_level; sibling: 'a tree };;
+
+               type 'a zipper = { tree : 'a starred_level; filler: 'a tree };;
 
                let rec move_botleft (z : 'a zipper) : 'a zipper =
                        (* returns z if the targetted node in z has no children *)
 
                let rec move_botleft (z : 'a zipper) : 'a zipper =
                        (* returns z if the targetted node in z has no children *)
index f07157f..14d5eed 100644 (file)
@@ -260,7 +260,7 @@ Recall back in [[Assignment4]], we asked you to enumerate the "fringe" of a leaf
         / \                  / \
        1   2                2   3
 
         / \                  / \
        1   2                2   3
 
-have the same fringe: `[1;2;3]`. We also asked you to write a function that determined when two trees have the same fringe. The way you approached that back then was to enumerate each tree's fringe, and then compare the two lists for equality. Today, and then again in a later class, we'll encounter two new ways to approach the problem of determining when two trees have the same fringe.
+have the same fringe: `[1;2;3]`. We also asked you to write a function that determined when two trees have the same fringe. The way you approached that back then was to enumerate each tree's fringe, and then compare the two lists for equality. Today, and then again in a later class, we'll encounter new ways to approach the problem of determining when two trees have the same fringe.
 
 
 Supposing you did work out an implementation of the tree zipper, then one way to determine whether two trees have the same fringe would be: go downwards (and leftwards) in each tree as far as possible. Compare the targetted leaves. If they're different, stop because the trees have different fringes. If they're the same, then for each tree, move rightward if possible; if it's not (because you're at the rightmost position in a sibling list), more upwards then try again to move rightwards. Repeat until you are able to move rightwards. Once you do move rightwards, go downwards (and leftwards) as far as possible. Then you'll be targetted on the next leaf in the tree's fringe. The operations it takes to get to "the next leaf" may be different for the two trees. For example, in these trees:
 
 
 Supposing you did work out an implementation of the tree zipper, then one way to determine whether two trees have the same fringe would be: go downwards (and leftwards) in each tree as far as possible. Compare the targetted leaves. If they're different, stop because the trees have different fringes. If they're the same, then for each tree, move rightward if possible; if it's not (because you're at the rightmost position in a sibling list), more upwards then try again to move rightwards. Repeat until you are able to move rightwards. Once you do move rightwards, go downwards (and leftwards) as far as possible. Then you'll be targetted on the next leaf in the tree's fringe. The operations it takes to get to "the next leaf" may be different for the two trees. For example, in these trees:
@@ -324,9 +324,10 @@ Here is how you can extract the components of a labeled record:
 
 Anyway, using record types, we might define the tree zipper interface like so:
 
 
 Anyway, using record types, we might define the tree zipper interface like so:
 
-       type 'a starred_tree = Root | Starring_Left of 'a starred_pair | Starring_Right of 'a starred_pair
-       and 'a starred_pair = { parent : 'a starred_tree; sibling: 'a tree }
-       and 'a zipper = { tree : 'a starred_tree; filler: 'a tree };;
+       type 'a starred_level = Root | Starring_Left of 'a starred_nonroot | Starring_Right of 'a starred_nonroot
+       and 'a starred_nonroot = { parent : 'a starred_level; sibling: 'a tree };;
+
+       type 'a zipper = { tree : 'a starred_level; filler: 'a tree };;
 
        let rec move_botleft (z : 'a zipper) : 'a zipper =
            (* returns z if the targetted node in z has no children *)
 
        let rec move_botleft (z : 'a zipper) : 'a zipper =
            (* returns z if the targetted node in z has no children *)