X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=week1.mdwn;h=52654e3ece5aa1ec8bdbfe84499a6bccfa602d1a;hp=5ae3e65f5c154f36a84432585178ed81bdb179ba;hb=367daadad3a5d40885072b6b6f66ffd397e29c91;hpb=9452f39dcc5b7babde45142e2b24e3617813d6a6 diff --git a/week1.mdwn b/week1.mdwn index 5ae3e65f..52654e3e 100644 --- a/week1.mdwn +++ b/week1.mdwn @@ -39,6 +39,24 @@ Basics of Lambda Calculus The lambda calculus we'll be focusing on for the first part of the course has no types. (Some prefer to say it instead has a single type---but if you say that, you have to say that functions from this type to this type also belong to this type. Which is weird.) +Here is its syntax: + +
+Variables:+ +Each variable is an expression. For any expressions M and N and variable a, the following are also expressions: + +x
,y
,z
... +
+Abstract: (λa M)
+
+
+We'll tend to write (λa M)
as just `(\a M)`, so we don't have to write out the markup code for the λ
. You can yourself write (λa M)
or `(\a M)` or `(lambda a M)`.
+
+
+Application: (M N)
+
+
Some authors reserve the term "term" for just variables and abstracts. We'll probably just say "term" and "expression" indiscriminately for expressions of any of these three forms.
Examples of expressions:
@@ -56,7 +74,7 @@ The lambda calculus has an associated proof theory. For now, we can regard the
proof theory as having just one rule, called the rule of **beta-reduction** or
"beta-contraction". Suppose you have some expression of the form:
- ((\ a M) N)
+ ((\a M) N)
that is, an application of an abstract to some other expression. This compound form is called a **redex**, meaning it's a "beta-reducible expression." `(\a M)` is called the **head** of the redex; `N` is called the **argument**, and `M` is called the **body**.
@@ -267,18 +285,15 @@ It's possible to enhance the lambda calculus so that functions do get identified
It's often said that dynamic systems are distinguished because they are the ones in which **order matters**. However, there are many ways in which order can matter. If we have a trivalent boolean system, for example---easily had in a purely functional calculus---we might choose to give a truth-table like this for "and":
-
-true and true = true
-true and true = true
-true and * = *
-true and false = false
-* and true = *
-* and * = *
-* and false = *
-false and true = false
-false and * = false
-false and false = false
-
+ true and true = true
+ true and * = *
+ true and false = false
+ * and true = *
+ * and * = *
+ * and false = *
+ false and true = false
+ false and * = false
+ false and false = false
And then we'd notice that `* and false` has a different intepretation than `false and *`. (The same phenomenon is already present with the material conditional in bivalent logics; but seeing that a non-symmetric semantics for `and` is available even for functional languages is instructive.)
@@ -523,7 +538,7 @@ Here's how it looks to say the same thing in various of these languages.
(let* [(bar (lambda (x) B))] M)
- then wherever `bar` occurs in `M` (and isn't rebound by a more local "let" or "lambda"), it will be interpreted as the function `(lambda (x) B)`.
+ then wherever `bar` occurs in `M` (and isn't rebound by a more local `let` or `lambda`), it will be interpreted as the function `(lambda (x) B)`.
Similarly, in OCaml:
@@ -583,8 +598,7 @@ Here's how it looks to say the same thing in various of these languages.
let x = A;;
... rest of the file or interactive session ...
- It's easy to be lulled into thinking this is a kind of imperative construction. *But it's not!* It's really just a shorthand for the compound "let"-expressions we've already been looking at, taking the maximum syntactically permissible scope. (Compare the "dot" convention in the lambda calculus, discussed above.)
-
+ It's easy to be lulled into thinking this is a kind of imperative construction. *But it's not!* It's really just a shorthand for the compound `let`-expressions we've already been looking at, taking the maximum syntactically permissible scope. (Compare the "dot" convention in the lambda calculus, discussed above.)
9. Some shorthand
@@ -656,9 +670,8 @@ Here's how it looks to say the same thing in various of these languages.
and there's no more mutation going on there than there is in:
-
- ∀x. (F x or ∀x (not (F x)))
-
+ ∀x. (F x or ∀x (not (F x)))
+
When a previously-bound variable is rebound in the way we see here, that's called **shadowing**: the outer binding is shadowed during the scope of the inner binding.
@@ -735,7 +748,7 @@ Or even:
(define foo B)
(foo 2)
-don't involve any changes or sequencing in the sense we're trying to identify. As we said, these programs are just syntactic variants of (single) compound syntactic structures involving "let"s and "lambda"s.
+don't involve any changes or sequencing in the sense we're trying to identify. As we said, these programs are just syntactic variants of (single) compound syntactic structures involving `let`s and `lambda`s.
Since Scheme and OCaml also do permit imperatival constructions, they do have syntax for genuine sequencing. In Scheme it looks like this: