From a9b6b232eb91e8db74289853cefcf50c77edf3f7 Mon Sep 17 00:00:00 2001 From: Jim Pryor Date: Fri, 26 Nov 2010 11:13:42 -0500 Subject: [PATCH] tweak zipper Signed-off-by: Jim Pryor --- zipper.mdwn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zipper.mdwn b/zipper.mdwn index ab16c0d0..10918343 100644 --- a/zipper.mdwn +++ b/zipper.mdwn @@ -228,7 +228,7 @@ We haven't given you a real implementation of the tree zipper, but only a sugges * Huet, Gerard. ["Functional Pearl: The Zipper"](http://www.st.cs.uni-sb.de/edu/seminare/2005/advanced-fp/docs/huet-zipper.pdf) Journal of Functional Programming 7 (5): 549-554, September 1997. * As always, [Oleg](http://okmij.org/ftp/continuations/Continuations.html#zipper) takes this a few steps deeper. -[[Same-fringe using a tree zipper]] +##Same-fringe using a tree zipper## 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: -- 2.11.0