formatting re Montague
[lambda.git] / topics / week13_coroutines_exceptions_and_aborts.mdwn
index de7e8c0..c8caa0d 100644 (file)
@@ -345,11 +345,11 @@ We can get that by some further rearranging of the code:
     in let outer_snapshot = fun box ->
         let foo_result = box
         in (foo_result) + 1000
-    in let continue_foo_normally = fun from_value ->
+    in let continue_foo_snapshot = fun from_value ->
         let value = from_value + 100
         in outer_snapshot value
     in (* start of foo_applied_to_x *)
-        if x = 1 then continue_foo_normally 10
+        if x = 1 then continue_foo_snapshot 10
         else outer_snapshot 20;;
 
 And this is indeed what is happening, at a fundamental level, when you use an expression like `abort 20`. Here is the original code for comparison:
@@ -374,15 +374,15 @@ You can think of them as functions that represent "how the rest of the computati
 
 The key idea behind working with continuations is that we're *inverting control*. In the fragment above, the code `(if x = 1 then ... else outer_snapshot 20) + 100`---which is written as if it were to supply a value to the outside context that we snapshotted---itself *makes non-trivial use of* that snapshot. So it has to be able to refer to that snapshot; the snapshot has to somehow be available to our inside-the-box code as an *argument* or bound variable. That is: the code that is *written* like it's supplying an argument to the outside context is instead *getting that context as its own argument*. He who is written as value-supplying slave is instead become the outer context's master.
 
-In fact you've already seen this several times this semester---recall how in our implementation of pairs in the untyped lambda-calculus, the handler who wanted to use the pair's components had *in the first place to be supplied to the pair as an argument*. So the exotica from the end of the seminar was already on the scene in some of our earliest steps. Recall also what we did with our [[abortable list traversals|/topics/week12_abortable_traversals]].
+In fact you've already seen this several times this semester---recall how in our implementation of pairs in the untyped lambda-calculus, the handler who wanted to use the pair's components had *in the first place to be supplied to the pair as an argument*. So the exotica from the end of the seminar was already on the scene in some of our earliest steps. Recall also what we did with our [[abortable list traversals|/topics/week12_abortable_traversals]]. (The `outer_snapshot` corresponds to the "done" handler in those traversals; and the `continue_foo_snapshot` to the "keep_going" handler.)
 
 This inversion of control should also remind you of Montague's treatment of determiner phrases in ["The Proper Treatment of Quantification in Ordinary English"](http://www.blackwellpublishing.com/content/BPL_Images/Content_store/Sample_chapter/0631215417%5CPortner.pdf) (PTQ).
 
-A naive semantics for atomic sentences will say the subject term is of type `e`, and the predicate of type `e -> t`, and that the subject provides an argument to the function expressed by the predicate.
+A naive semantics for atomic sentences will say the subject term is of type `e`, and the predicate of type `e -> t`, and that the subject provides an argument to the function expressed by the predicate.
 
-Monatague proposed we instead take the subject term to be of type `(e -> t) -> t`, and that now it'd be the predicate (still of type `e -> t`) that provides an argument to the function expressed by the subject.
+Monatague proposed we instead take the subject term to be of type `(e -> t) -> t`, and that now it'd be the predicate (still of type `e -> t`) that provides an argument to the function expressed by the subject.
 
-If all the subject did then was supply an `e` to the `e -> t` it receives as an argument, we wouldn't have gained anything we weren't already able to do. But of course, there are other things the subject can do with the `e -> t` it receives as an argument. For instance, it can check whether anything in the domain satisfies that `e -> t`; or whether most things do; and so on.
+If all the subject did then was supply an `e` to the `e -> t` it receives as an argument, we wouldn't have gained anything we weren't already able to do. But of course, there are other things the subject can do with the `e -> t` it receives as an argument. For instance, it can check whether anything in the domain satisfies that `e -> t`; or whether most things do; and so on.
 
 This inversion of who is the argument and who is the function receiving the argument is paradigmatic of working with continuations.
 
@@ -404,11 +404,11 @@ into this:
     in let outer_snapshot = fun box ->
         let foo_result = box
         in (foo_result) + 1000
-    in let continue_foo_normally = fun from_value ->
+    in let continue_foo_snapshot = fun from_value ->
         let value = from_value + 100
         in outer_snapshot value
     in (* start of foo_applied_to_x *)
-        if x = 1 then continue_foo_normally 10
+        if x = 1 then continue_foo_snapshot 10
         else outer_snapshot 20;;
 
 Code written in the latter form is said to be written in **explicit continuation-passing style** or CPS. Later we'll talk about algorithms that mechanically convert an entire program into CPS.
@@ -442,10 +442,10 @@ There are also different kinds of "syntactic sugar" we can use to hide the conti
       let outer_snapshot = fun box ->
           let foo_result = box
           in (foo_result) + 1000
-      in let continue_foo_normally = fun from_value ->
+      in let continue_foo_snapshot = fun from_value ->
           let value = from_value + 100
           in outer_snapshot value
-      in if x = 1 then continue_foo_normally 10
+      in if x = 1 then continue_foo_snapshot 10
       else outer_snapshot 20;;
 
 # let test_shift x =