edits
[lambda.git] / topics / _week15_continuation_applications.mdwn
index eeb397b..cc5c9e2 100644 (file)
@@ -13,14 +13,14 @@ zippers, then as a monad.  In this lecture, we will generalize
 continuations slightly beyond a monad, and then begin to outline some
 of the applications of monads.  In brief, the generalization can be
 summarized in terms of types: instead of using a Kleisli arrow mapping
-a type α to a continuized type α -> ρ -> ρ, we'll allow the result
-types to differ, i.e., we'll map α to α -> β -> γ.  This will be
+a type α to a continuized type (α -> ρ) -> ρ, we'll allow the result
+types to differ, i.e., we'll map α to (α -> β) -> γ.  This will be
 crucial for some natural language applications.
 
 Many (though not all) of the applications are discussed in detail in
 Barker and Shan 2014, *Continuations in Natural Language*, OUP.
 
-In terms of list zippers, the continuation of a focussed element in
+In terms of list zippers, the continuation of a focused element in
 the list is the front part of the list.
 
     list zipper for the list [a;b;c;d;e;f] with focus on d:
@@ -31,7 +31,7 @@ the list is the front part of the list.
      continuation
 
 In terms of tree zippers, the continuation is the entire context of
-the focussed element--the entire rest of the tree.
+the focused element--the entire rest of the tree.
 
 [drawing of a broken tree]
 
@@ -45,15 +45,16 @@ We'll burn through that conceptual fog today.  The natural thing to
 try would have been to defunctionalize the continuation-based solution
 using a tree zipper.  But that would not have been easy, since the
 natural way to implement the doubling behavior of the shifty operator
-would have been to simply copy the context provided by the zipper.
+would have been to simply copy the context provided by the zipper.  
 This would have produced two uncoordinated copies of the other shifty
 operator, and we'd have been in the situation described in class of
 having a reduction strategy that never reduced the number of shifty
-operators below 2.
+operators below 2. (There are ways around this limitation of tree zippers, 
+but they are essentially equivalent to the technique given just below.)
 
 Instead, we'll re-interpreting what the continuation monad was doing
-in defunctionalized terms by using Quantifier Raising (a technique
-from linguistics).
+in more or less defunctionalized terms by using Quantifier Raising, a technique
+from linguistics.
 
 But first, motivating quantifier scope as a linguistic application.
 
@@ -69,7 +70,7 @@ a scope-taking expression to take scope.
     2. For every x, [Ann put a copy of x's homeworks in her briefcase]
 
 The sentence in (1) can be paraphrased as in (2), in which the
-quantificational DP *every student* takes scope over the rest of the sentence.
+quantificational DP *everyone* takes scope over the rest of the sentence.
 Even if you suspect that there could be an analysis of (2) on which
 "every student's term paper" could denote some kind of mereological
 fusion of a set of papers, it is much more difficult to be satisfied
@@ -103,11 +104,14 @@ Raising closely resembles the reduction rule for shift:
     Quantifier Raising: given a sentence [... [QDP] ...], build a new
     sentence [QDP (\x.[... [x] ...])].  
 
+Here, QDP is a scope-taking quantificational DP.
+
 Just to emphasize the similarity between QR and shift, we can use QR
 to provide insight into the tree task that mystified us earlier.
 
 \tree (. (a)((S)((d)((S)(e)))))
 
+<pre>
   .
 __|___
 |    |
@@ -118,11 +122,13 @@ a  __|___
       d  _|__
          |  |
          S  e
+</pre>
 
 First we QR the lower shift operator
 
 \tree (. (S) ((\\x) ((a)((S)((d)((x)(e)))))))
 
+<pre>
    .
 ___|___
 |     |
@@ -137,11 +143,13 @@ S  ___|___
              d  _|__
                 |  |
                 x  e
+</pre>
 
 Next, we QR the upper shift operator
 
 \tree (. (S) ((\\y) ((S) ((\\x) ((a)((y)((d)((x)(e)))))))))
 
+<pre>
    .
 ___|___
 |     |
@@ -160,6 +168,7 @@ S  ___|____
                     d  _|__
                        |  |
                        x  e
+</pre>
 
 We then evaluate, using the same value for the shift operator proposed before:
 
@@ -173,6 +182,7 @@ form:
 
 \tree (. (S) ((\\y) ((a)((y)((d)(((a)((y)((d)(("")(e)))))(e)))))))
 
+<pre>
    .
 ___|___
 |     |
@@ -195,6 +205,7 @@ S  ___|____
                     d  __|__
                        |   |
                        ""  e
+</pre>
 
 
 Repeating the process for the upper shift operator replaces each
@@ -202,6 +213,7 @@ occurrence of y with a copy of the whole tree.
 
 \tree (. ((a)((((a)(("")((d)(((a)(("")((d)(("")(e)))))(e))))))((d)(((a)((((a)(("")((d)(((a)(("")((d)(("")(e)))))(e))))))((d)(("")(e)))))(e))))))
 
+<pre>
       .
       |
 ______|______
@@ -234,8 +246,10 @@ a  ___|____           |      |
                                  d  __|__
                                     |   |
                                     ""  e
+</pre>
 
-The yield of this tree (the sequence of leaf nodes) is aadadeedaadadeedee.
+The yield of this tree (the sequence of leaf nodes) is
+aadadeedaadadeedee, which is the expected output of the double-shifted tree.
 
 Exercise: the result is different, by the way, if the QR occurs in a
 different order.
@@ -284,15 +298,14 @@ manipulates a list of information.  It is natural to imagine
 separating a box into two regions, the payload and the hidden scratch
 space:
 
+<pre>
     _______________               _______________           _______________ 
     | [x->2, y->3] |             | [x->2, y->3] |          | [x->2, y->3] |
   -------------------          ------------------         ------------------
     |              |     ¢        |              |    =     |              |
     |    +2        |             |     y        |          |     5        |
     |______________|             |______________|          |______________|
-
-
-(Imagine the + operation has been lifted into the Reader monad too.)
+</pre>
 
 For people who are familiar with Discourse Representation Theory (Kamp
 1981, Kamp and Reyle 1993), this separation of boxes into payload and