edits
[lambda.git] / assignment10.mdwn
index 97d2098..8f52ca2 100644 (file)
@@ -9,10 +9,29 @@
        >       it with.
 
 
+       As Ken Shan points out, this is an instance of the algorithm
+       for converting name/year citations (like 'v. Montague 1970')
+       to numerals corresponding to their ('v. [24]').  Except that
+       bibliograpic numerals don't start with zero.
+
+       Give some thought to efficiency: there are straightforward
+       solutions that involve traversing the tree once (in order to,
+       say, construct a suitable mapping from leafs to ints), then
+       traversing it again to do the conversion.  Can you find a
+       solution that traverses the tree exactly once, replacing each
+       leaf as soon as you see it?
+
+       Consider a variation in which you must replace each leaf with
+       is number of occurrences in the tree.  Is there any way to do
+       that with a single traversal?
+
+       You can assume that the tree is leaf-labeled (no labels on the
+       internal nodes), and that the leafs are, say, chars.
+
        Here is [a hint](/hints/assignment_10_hint).
 
 
-2.     Armed with your solution to problem 1, try this: you have as input a lead-labeled, binary tree whose labels are strings. You also have as input an interpretation function from strings to meanings. Let the meanings of your strings be primitive elements, for instance:
+2.     Armed with your solution to problem 1, try this: you have as input a leaf-labeled, binary tree whose labels are strings. You also have as input an interpretation function from strings to meanings. Let the meanings of your strings be primitive elements, for instance:
 
                type meaning = John | Bill | Sally | Zachariah | Swam | Likes | ...
 
@@ -39,7 +58,7 @@
 
        That won't compile in OCaml because we use the `M`s in a way that's intuitive but unrecognized by OCaml. What OCaml will recognize is more complex. Don't worry; you won't need to code a general implementation of StateT.
 
-       What we do want you to do is to implement StateT(List). That is, plug in the implementations of the List monad's type, unit, and bind into the preceding definitions. That will be a monad, consisting of an inner List monad with StateT packaging around it. Choose sensible names for the type, and unit, bind, and elevant functions of your StateT(List) monad.
+       What we do want you to do is to implement StateT(List). That is, plug in the implementations of the List monad's type, unit, and bind into the preceding definitions. That will be a monad, consisting of an inner List monad with StateT packaging around it. Choose sensible names for the type, and unit, bind, and elevate functions of your StateT(List) monad.
 
        You may want to write some operations for your List monad, such as:
 
 
        Now, go back to the GS&V assignment from [[assignment7]]. Does the monad you've now crafted enable you to code your implementation of that semantics more elegantly? You can begin by using a composite store of the same sort we used in the hints: a pair of an assignment function `r` and some `h` that associates pegs with entities.
 
-Is the `h` really essential to your solution? Or could you do everything with a store consisting of a single mapping from variables to entities? (You'd still be working with a State monad, but without the pegs.) Explain why or why not.
+       Is the `h` really essential to your solution? Or could you do everything with a store consisting of a single mapping from variables to entities? (You'd still be working with a State monad, but without the pegs.) Explain why or why not.
 
 4.     The next two exercises were taken from _The Little Schemer_ Chapter 8.
 
-               Suppose `lst` is a list of Scheme symbols (`'symbols 'are 'things 'written 'like 'this`; a list of them is `'(written like this)`). And that the behavior of `(remove 'sym lst)` is to remove every occurrence of `'sym` from `lst`.
+       Suppose `lst` is a list of Scheme symbols (`'symbols 'are 'things 'written 'like 'this`; a list of them is `'(written like this)`). And that the behavior of `(remove 'sym lst)` is to remove every occurrence of `'sym` from `lst`.
 
-       Now we define a function `remove-co` which has the following behavior. It accepts as arguments a symbol, a list, and a handler `k` (I wonder why we named it that). `remove-co` calls `k` with two arguments: first, a list of all the sumbols in `lst` that aren't equal to `'sym`, and second, a list of all the symbols in `lst` that are equal to `'sym` (the handler might want to, for example, see what the length of the latter list is).
+       Now we define a function `remove-co` which has the following behavior. It accepts as arguments a symbol, a list, and a handler `k` (I wonder why we named it that). `remove-co` calls `k` with two arguments: first, a list of all the symbols in `lst` that aren't equal to `'sym`, and second, a list of all the symbols in `lst` that are equal to `'sym` (the handler might want to, for example, see what the length of the latter list is).
 
        Here is a partial implementation. You should fill in the blanks. If you get stuck, you can consult the walkthough in _The Little Schemer_, or talk to us.
 
@@ -93,7 +112,19 @@ Is the `h` really essential to your solution? Or could you do everything with a
                       (insert-co new before after (cdr lst) (lambda (new-lst lefts rights) ________))))))
 
 
-6.     Go back to the "abSd" problem we presented in [[From List Zippers to Continuations]]. Consider the "tc" solution which uses explicitly passed continuations. Try to reimplement this using reset and shift instead of having an explicit `k` argument. This will likely be challenging but rewarding. The notes on [[CPS and Contunuation Operators]], especially the examples at the end, should be helpful. We are of course also glad to help you out.
+6.     Go back to the "abSd" problem we presented in [[From List Zippers to Continuations]]. Consider the "tc" solution which uses
+explicitly passed continuations. Try to reimplement this using reset
+and shift instead of having an explicit `k` argument. This will likely
+be challenging but rewarding. The notes on [[CPS and Continuation Operators]], especially the examples at the end, should be helpful. We
+are of course also glad to help you out.
+
+    Consider adding a special symbol `'#'` (pronounced 'prompt') to the
+    mini-language such that
+
+    `"ab#cdSef"` ~~> `"abcdcdef"`
+
+    That is, the rule for `'S'` is to copy the preceding string, but
+    only up to the closest enclosing `'#'` symbol.
 
 7.     Can you reimplement your solution to [[assignment9]] using reset and shift?