From 8fbf14566363197bb08307a6bf4daece2f27602e Mon Sep 17 00:00:00 2001 From: Jim Pryor Date: Tue, 30 Nov 2010 11:25:48 -0500 Subject: [PATCH 1/1] week11 tweaks Signed-off-by: Jim Pryor --- assignment8.mdwn | 7 ++++--- week11.mdwn | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/assignment8.mdwn b/assignment8.mdwn index 495ef2f7..59e0090b 100644 --- a/assignment8.mdwn +++ b/assignment8.mdwn @@ -2,9 +2,10 @@ 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 *) diff --git a/week11.mdwn b/week11.mdwn index f07157f1..14d5eed2 100644 --- a/week11.mdwn +++ b/week11.mdwn @@ -260,7 +260,7 @@ Recall back in [[Assignment4]], we asked you to enumerate the "fringe" of a leaf / \ / \ 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: @@ -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: - 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 *) -- 2.11.0