post Introducing Monads
[lambda.git] / index.mdwn
1 # Seminar in Semantics / Philosophy of Language #
2
3 or: **What Philosophers and Linguists Can Learn From Theoretical Computer Science But Didn't Know To Ask**
4
5 This course is co-taught by [Chris Barker](http://homepages.nyu.edu/~cb125/) and [Jim Pryor](http://www.jimpryor.net/). Linguistics calls it "LING-GA 3340" and Philosophy calls it "PHIL-GA 2296".
6 The seminar meets in spring 2015 on Thursdays from 4 until a bit before 7 (with a short break in the middle), in
7 the Linguistics building at 10 Washington Place, in room 103 (front of the first floor).
8
9 One student session to discuss homeworks will be held every Wednesday from 5-6, in Linguistics room 104 (back of the first floor).
10
11 ## [[Index of Main Content|content]] (lecture notes and more) ##
12
13 ## [[Offsite Readings|readings]] ##
14
15 ## Announcements ##
16
17 *   [[Untyped lambda calculus evaluator|code/lambda_evaluator]] on this site
18
19 *   This wiki will be undergoing lots of changes throughout the semester, and particularly in these first few days as we get it set up, migrate over some of the content from the previous time
20 we taught this course, and iron out various technical wrinkles. Please be patient. When you sit down to read the wiki, it's a good idea to always hit "Refresh" in your browser to make sure you're reading the latest additions and refinements of the website. (Sometimes these will be tweaks, other times very substantial. Updates will happen at miscellaneous hours, sometimes many times in a given day.)
21
22     If you're eager to learn, though, you don't have to wait on us to be ready to serve you. You can go look at the [archived first version](http://lambda1.jimpryor.net) of this course. Just keep in mind that
23 the text and links there haven't been updated. And/or you can get started on installing the software and ordering some of the books.
24
25 *   As we mentioned in class, if you're following the course and would like to be emailed occasionally, send an email to <mailto:jim.pryor@nyu.edu>, saying "lambda" in the subject line. Most often, we will just post announcements to this website, rather than emailing you. But occasionally an email might be more appropriate.
26
27 <!--
28 *   As we mentioned in class, we're also going to schedule a session to discuss the weekly homeworks. If you'd like to participate in this, please complete [this Doodle poll](http://doodle.com/7xrf4w8xq4i9e5za). It asks when you are available on Tuesdays and Wednesdays.
29 -->
30
31 *   The student session has been scheduled for Wednesdays from 5-6, in Linguistics room 104 (back of the first floor).
32
33     Those of you interested in additional Q&amp;A but who can't make that time, let us know.
34
35     You should see these student sessions as opportunities to clear up lingering
36 issues from material we've discussed, and help get a better footing for what
37 we'll be doing the next week. It's expected you'll have made at least a serious start on that
38 week's homework (due the following day) before the session.
39
40 *   Here is information about [[How to get the programming languages running on your computer|installing]]. If those instructions seem overwhelming, note that it should be possible to do a lot of this course using only demonstration versions of these languages [[that run in your web browser|browser]].
41
42 *   Henceforth, unless we say otherwise, every homework will be "due" by
43 Wednesday morning after the Thursday seminar in which we refer to it.
44 (Usually we'll post the assignment shortly before the seminar, but don't
45 rely on this.) However, for every assignment there will be a "grace
46 period" of one further week for you to continue working on it if you
47 have trouble and aren't able to complete the assignment to your
48 satisfaction by the due date. You shouldn't hesitate to talk to us---or
49 each other!---about the assignments when you do have trouble. We don't
50 mind so much if you come across answers to the assignment when browsing
51 the web, or the Little Schemer book, or anywhere. So long as you can
52 reason yourself through the solutions and experience for yourself the
53 insights they embody.
54
55     We reserve the privilege to ruthlessly require you to
56 explain your solutions in conversations at any point, in section or in
57 class.
58
59     You should always *aim* to complete the assignments by the "due" date,
60 as this will fit best with the progress of the seminar.
61
62     The assignments will tend to be quite challenging. Again, you should by
63 all means talk amongst yourselves, and to us, about strategies and
64 questions that come up when working through them.
65
66     We will not always be able to predict accurately which problems are
67 easy and which are hard.  If we misjudge, and choose a problem that is
68 too hard for you to complete to your own satisfaction, it is still
69 very much worthwhile (and very much appreciated) if you would explain
70 what is difficult, what you tried, why what you tried didn't work, and
71 what you think you need in order to solve the problem.
72
73
74
75
76 (**Week 1**) Thursday 29 Jan 2015
77
78 > Topics:
79 [[Order in programming languages and natural language|topics/week1 order]];
80 [[Introduction to functional programming|topics/week1 kapulet intro]];
81 [[Homework|exercises/assignment1]];
82 [[Advanced notes|topics/week1 kapulet advanced]]
83
84 (**Intermezzo**)
85 > Help on [[learning Scheme]], [[OCaml|learning OCaml]], and [[Haskell|learning Haskell]];
86 The [[differences between our made-up language and Scheme, OCaml, and Haskell|rosetta1]];
87 [[What do words like "interpreter" and "compiler" mean?|ecosystem]] (in progress)
88
89 (**[[Lambda Evaluator|code/lambda evaluator]]**) Usable in your browser. It can help you check whether your answer to some of the (upcoming) homework questions works correctly.
90 <!--
91  There is also now a [library](/lambda library) of lambda-calculus arithmetical and list operations, some relatively advanced.
92 -->
93
94 (**Week 2**) Thursday 5 February 2015
95 > Topics:
96 [[Intro to the Lambda Calculus|topics/week2 lambda intro]];
97 [[Advanced notes|topics/week2 lambda advanced]];
98 [[Encoding Booleans, Tuples, Lists, and Numbers|topics/week2 encodings]];
99 [[Homework|exercises/assignment2]]
100
101 > Also, if you're reading the Hankin book, try reading Chapters 1-3. You will most likely need to come back again and read it multiple times; but this would be a good time to make the first attempt.
102
103 > We posted [[answers to Week 1's homework|exercises/assignment1_answers]].
104
105 (**Week 3**) Thursday 12 February 2015
106 *We will continue to develop these notes over the next few days.*
107
108 > Topics:
109 [[Arithmetic with Church numbers|topics/week3_church_arithmetic]];
110 [[More on Lists|topics/week3 lists]] (expanded on Sunday);
111 [[What is computation?|topics/week3_what_is_computation]];
112 [[Reduction Strategies and Normal Forms|topics/week3_evaluation_order]] (posted on Monday 23 Feb);
113 [[Unit and its usefulness|topics/week3 unit]] (posted on Wednesday);
114 [[Combinatory Logic|topics/week3 combinatory logic]] (revised on Monday and Tuesday);
115 [[Homework|exercises/assignment3]]
116
117 > Also, by this point you should be able to handle all of *The Little Schemer* except for Chapters 9 and 10. Chapter 9 covers what is going on under the hood with `letrec`, and that will be our topic for next week. You can also read Chapter 4 of Hankin on Combinatory Logic.
118
119 > We posted [[answers to Week 2's homework|exercises/assignment2_answers]].
120
121 (**Week 4**) Thursday 19 February 2015
122
123 > Topics: [[!img images/tabletop_roleplaying.png size="240x240" alt="Hey, no recursing"]]
124 [[Yes, recursing|topics/week4_fixed_point_combinators]];
125 [[More about fixed point combinators|topics/week4_more_about_fixed_point_combinators]];
126 Towards types (in progress);
127 [[Homework|exercises/assignment4]]
128
129 > Now you can read Sections 3.1 and 6.1 of Hankin; and browse the rest of Hankin Chapter 6, which should look somewhat familiar.
130
131 > If you're reading along in the Pierce book, we've now covered much of the material in his Chapters 1-7.
132
133 > We posted [[answers to Week 3's homework|exercises/assignment3_answers]].
134
135 (**Week 5**) Thursday 26 February 2015
136
137 > *Note*: Jim will be updating and expanding the lecture notes by Tuesday, but doesn't want to delay any longer letting you have access to the drafts we (in part) presented from in seminar. But do come back and re-read the pages when the expanded versions are posted.
138
139 > Topics:
140 [[Simply-typed lambda calculus|topics/week5 simply typed]];
141 [[System F|topics/week5 system F]];
142 Types in OCaml and Haskell;
143 Practical advice for working with OCaml and/or Haskell (all will be posted soon);
144 [[Homework|exercises/assignment5]]
145
146 > *There is some assigned reading for our next meeting.* This comes in two batches. The first batch consists of [[this footnote|readings/kaplan-plexy.pdf]] from Kaplan's *Demonstratives*. Also recommended, but not mandatory, is [[this selection|readings/king-on-schiffer.pdf]] from Chapter 4 of Jeff King's 2007 book *The Nature and Structure of Content*. The second batch consists of [[this paper|readings/rieppel-beingsthg.pdf]] from Michael Rieppel, a recent Berkeley Philosophy PhD, on Frege's "concept horse" problem. Also recommended, but not mandatory, is [[this selection|readings/king-on-logicism.pdf]] from Chapter 5 of King's book. (It reviews and elaborates his paper "[Designating propositions](http://philpapers.org/rec/KINDP)".)
147
148 > If you're interested in the scholarly background on Frege's "concept horse" problem, here is [an entry point](http://philpapers.org/rec/PROWIF).
149
150 > If you're reading along in Hankin, you can look at Chapter 7.
151
152 > If you're reading along in the Pierce book, the chapters most relevant to this week's discussion are 22 and 23; though for context we also recommend at least Chapters 8, 9, 11, 20, and 29. We don't expect most of you to follow these recommendations now, or even to be comfortable enough yet with the material to be able to. We're providing the pointers as references that some might conceivably pursue now, and others later.
153
154 (**Week 6**) Thursday March 5
155
156 > We will be discussing the readings posted above.
157
158 > Topics: [[Kaplan on Plexy|topics/week6_plexy]]; King on that-clauses and "the proposition that P"; Rieppel on Frege and the concept HORSE
159
160 (**Week 7**) Thursday March 12
161
162 > Topics: [[Combinatory evaluator|topics/week7_combinatory_evaluator]]; Interpreter for Lambda terms; [[Introducing Monads|topics/week7_introducing_monads]]
163
164
165 <!--
166 We've added a [[Monad Library]] for OCaml.
167 We've posted a [[State Monad Tutorial]].
168 -->
169
170
171 ## Course Overview ##
172
173 The overarching goal of this seminar is to introduce concepts and techniques from
174 theoretical computer science and show how they can provide insight
175 into established philosophical and linguistic problems.
176
177 This is not a seminar about any particular technology or software.
178 Rather, it's about a variety of conceptual/logical ideas that have been
179 developed in computer science and that linguists and philosophers ought to
180 know, or may already be unknowingly trying to reinvent.
181
182 Philosphers and linguists tend to reuse the same familiar tools in
183 ever more (sometime spectacularly) creative ways.  But when your only
184 hammer is classical logic, every problem looks like modus ponens.  In
185 contrast, computer scientists have invested considerable ingenuity in
186 studying the design of their conceptual tools (among other things), and they've made much progress that we can benefit from.
187
188 "Why shouldn't I reinvent some idea X for myself? It's intellectually
189 rewarding!" Yes it is, but it also takes time you might have better
190 spent elsewhere. After all, you can get anywhere you want to go by walking, but you can
191 accomplish more with a combination of walking and strategic subway
192 rides.
193
194 More importantly, the idiosyncrasies of your particular
195 implementation may obscure what's fundamental to the idea you're
196 working with. Your implementation may be buggy in corner cases you
197 didn't think of; it may be incomplete and not trivial to generalize; its
198 connection to existing literature and neighboring issues may go
199 unnoticed. For all these reasons you're better off understanding the
200 state of the art.
201
202 The theoretical tools we'll be introducing aren't part of the diet of most
203 everyday programmers, but they are prominent in academic computer science,
204 especially in the fields of functional programming and type theory.
205
206 Of necessity, this course will lay a lot of logical groundwork. But throughout
207 we'll be aiming to mix that groundwork with real cases
208 in our home subjects where these tools can (or already do, covertly) play central roles.
209
210 Our aim for the
211 course is to enable you to make these tools your own; to have enough
212 understanding of them to recognize them in use, use them yourself at least
213 in simple ways, and to be able to read more about them when appropriate.
214
215 "Computer Science is no more about computers than astronomy is about telescopes." -- [E. W. Dijkstra](https://en.wikipedia.org/wiki/Edsger_W._Dijkstra) <small>(or Hal Abelson, or Michael Fellows; the quote's <a href="https://en.wikiquote.org/wiki/Computer_science">origins are murky</a>)</small>
216
217
218 [[More about the topics and larger themes of the course|overview]]
219
220
221 ## Who Can Participate? ##
222
223 The course will not presume previous experience with programming.  We
224 will, however, discuss concepts embodied in specific programming
225 languages, and we will encourage experimentation with running,
226 modifying, and writing computer programs.
227
228 The course will not presume lots of mathematical or logical background, either.
229 However, it will demand a certain amount of comfort working with such material; as a result,
230 it will not be especially well-suited to be a first graduate-level course
231 in formal semantics or philosophy of language. If you have concerns about your
232 background, come discuss them with us.
233
234 If you hope to have the class satisfy the logic requirement for Philosophy PhD students, this needs to be discussed with us and approved in advance. If this would be
235 your first or only serious
236 engagement with graduate-level formal work you should consider
237 carefully, and must discuss with us, (1) whether you'll be adequately
238 prepared for this course, and (2) whether you'd be better served by
239 taking a logic course
240 with a more canonical syllabus.
241 This term you could take PHIL-GA 1003, [Logic for Philosophers](http://jdh.hamkins.org), offered by Joel Hamkins on Wednesdays 12-2.
242
243 Faculty and students from outside of NYU Linguistics and Philosophy are welcome
244 to audit, to the extent that this coheres well with the needs of our local
245 students.
246
247
248 ## Recommended Software ##
249
250 During the course, we'll be encouraging you to try out various things in Scheme
251 and OCaml. Occasionally we will also make remarks about Haskell. All three of these
252 are prominent *functional programming languages*. The term "functional" here means they have
253 a special concern with functions, not just that they aren't broken. But what precisely is
254 meant by "functional" is somewhat fuzzy and even its various precisifications take some
255 time to explain. We'll get clearer on this during the course. Another term used roughly the same as "functional"
256 is "declarative." At a first pass, "functional" or "declarative" programming is primarily focused on complex
257 expressions that get computationally evaluated to some (usually simpler) result. In class I gave the examples
258 of `1+2` (which gets evaluated in arithmetic to `3`), `1+2 < 5` (which gets evaluated in arithmetic to a truth-value), and `1`
259 (which gets evaluated in arithmetic to `1`). Also Google search strings, which get evaluated by Google servers to a
260 list of links.
261
262 The dominant contrasting class of programming languages (the great majority of what's used
263 in industry) are called "imperatival" languages, meaning they have more to do with following a sequence of commands (generating what we
264 called in class "side-effects", though sometimes what they're *alongside* is not that interesting, and all the focus is instead
265 on the effects). Programming languages like C and Python and JavaScript and so on are predominantly of this sort.
266
267 In truth, nothing that gets marketed as a "programming language" is really completely 100% functional/declarative, and even the
268 languages I called "imperatival" will have some "functional" *fragments* (they evaluate `1+2` to `3`, also). So these labels aren't
269 strictly exclusive. The labels are better thought of as concerning different
270 *styles* or *idioms* of programming. Languages like Scheme and OCaml and especially Haskell get called "functional languages" because
271 of the extent to which they emphasize, and are designed around those idioms. Languages like Python and JavaScript are sometimes themselves
272 described as "more functional" than other languages, like C.
273
274 In any case, here is
275 <a name=installing></a>
276 [[How to get the programming languages running on your computer|installing]].
277 And here is some more context for the three languages we will be focusing on:
278
279 *   **Scheme** is one of two or three major dialects of *Lisp*, which is a large family
280 of programming languages. Scheme
281 is the more clean and minimalist dialect of Lisp, and is what's mostly used in
282 academic circles.
283 Scheme itself has umpteen different "implementations", which share most of
284 their fundamentals, but have slightly different extensions and interact with
285 the operating system differently. One major implementation is called Racket,
286 and that is what we recommend you use. If you're already using or comfortable with
287 another Scheme implementation, though, there's no compelling reason to switch.
288
289     Another good Scheme implementation is Chicken. For our purposes, this is in some
290 respects superior to Racket, and in other respects inferior. <!--
291 Racket doesn't have R7RS-small, and won't anytime soon. :-(
292 Also Chicken's library collection seems stronger, or at least better organized and maintained.
293 Other R7RS-friendly: [Gauche](http://practical-scheme.net/gauche), [Chibi](https://code.google.com/p/chibi-scheme).
294 -->
295
296     Racket and Chicken stand to Scheme in something like the relation Firefox stands to HTML.
297
298     (Wikipedia on
299 [Lisp](http://en.wikipedia.org/wiki/Lisp_%28programming_language%29),
300 [Scheme](http://en.wikipedia.org/wiki/Scheme_%28programming_language%29),
301 [Racket](http://en.wikipedia.org/wiki/Racket_%28programming_language%29), and
302 [Chicken](http://en.wikipedia.org/wiki/CHICKEN_%28Scheme_implementation%29).)  
303     (Help on [[Learning Scheme]])
304
305 *   **Caml** is one of two major dialects of *ML*, which is another large
306 family of programming languages. Caml has only one active "implementation",
307 OCaml, developed by the INRIA academic group in France. Sometimes we may refer to Caml or ML
308 more generally; but you can assume that what we're talking about always works more
309 specifically in OCaml.
310
311     (Wikipedia on
312 [ML](http://en.wikipedia.org/wiki/ML_%28programming_language%29),
313 [Caml](http://en.wikipedia.org/wiki/Caml), and
314 [OCaml](http://en.wikipedia.org/wiki/OCaml).)  
315     (Help on [[Learning OCaml]])
316
317
318 *   **Haskell** is also used a
319 lot in the academic contexts we'll be working through. Its surface syntax
320 differs from Caml, and there are various important things one can do in
321 each of Haskell and Caml that one can't (or can't as easily) do in the
322 other. But these languages also have *a lot* in common, and if you're
323 familiar with one of them, it's generally not hard to move between it and the
324 other.
325
326     Like Scheme, Haskell has a couple of different implementations. The
327 dominant one, and the one we recommend you install, is called GHC, short
328 for "Glasgow Haskell Compiler".
329
330     (Wikipedia on
331 [Haskell](http://en.wikipedia.org/wiki/Haskell_%28programming_language%29) and
332 [GHC](https://en.wikipedia.org/wiki/Glasgow_Haskell_Compiler).)  
333     (Help on [[Learning Haskell]])
334
335 <!--
336 [Helium](https://www.haskell.org/pipermail/haskell/2003-January/011071.html) is a simplified Haskell for teaching (no typeclasses)
337 -->
338
339
340
341 ## Recommended Books ##
342
343 It's not *mandatory* to purchase these for the class. But they are good ways to get a more thorough and solid understanding of some of the more basic conceptual tools we'll be using. We especially recommend the first three of them.
344
345 *   *An Introduction to Lambda Calculi for Computer Scientists*, by Chris
346 Hankin, currently $18 paperback on
347 [Amazon](http://www.amazon.com/dp/0954300653).
348
349 *   *The Little Schemer, Fourth Edition*, by Daniel P. Friedman and Matthias
350 Felleisen, currently $29 paperback on [Amazon](http://www.amazon.com/exec/obidos/ASIN/0262560992).
351 This is a classic text introducing the gentle art of programming, using the
352 functional programming language Scheme. Many people love this book, but it has
353 an unusual dialog format that is not to everybody's taste. **Of particular
354 interest for this course** is the explanation of the Y combinator, available as
355 a free sample chapter [at the MIT Press web page for the
356 book](http://www.ccs.neu.edu/home/matthias/BTLS/).
357
358 *   *The Seasoned Schemer*, also by Daniel P. Friedman and Matthias Felleisen, currently $29 paperback
359 on [Amazon](http://www.amazon.com/Seasoned-Schemer-Daniel-P-Friedman/dp/026256100X). This is a sequel to The Little Schemer, and it focuses on mutation and continuations in Scheme. We will be covering those topics in the second half of the course.
360
361 *   *The Little MLer*, by Matthias Felleisen and Daniel P. Friedman, currently $31 paperback / $29 kindle
362 on [Amazon](http://www.amazon.com/Little-MLer-Matthias-Felleisen/dp/026256114X).
363 This covers much of the same introductory ground as The Little Schemer, but
364 this time in a dialect of ML. It doesn't use OCaml, the dialect we'll be working with, but instead another dialect of ML called SML. The syntactic differences between these languages is slight.
365 ([Here's a translation manual between them](http://www.mpi-sws.org/~rossberg/sml-vs-ocaml.html).)
366 Still, that does add an extra layer of interpretation, and you might as well
367 just use The Little Schemer instead. Those of you who are already more
368 comfortable with OCaml (or with Haskell) than with Scheme might consider
369 working through this book instead of The Little Schemer. For the rest of you,
370 or those of you who *want* practice with Scheme, go with The Little Schemer.
371
372 *   *The Haskell Road to Logic, Math and Programming*, by Kees Doets and Jan van Eijck, currently $22 on [Amazon](http://www.amazon.com/dp/0954300696) is a textbook teaching the parts of math and logic we cover in the first few weeks of Logic for Philosophers. (Notions like validity, proof theory for predicate logic, sets, sequences, relations, functions, inductive proofs and recursive definitions, and so on.) The math here should be accessible and familiar to all of you. What is novel about this book is that it integrates the exposition of these notions with a training in (part of) Haskell. It only covers the rudiments of Haskell's type system, and doesn't cover monads; but if you wanted to review this material and become comfortable with core pieces of Haskell in the process, this could be a good read.
373 (The book also seems to be available online [here](http://fldit-www.cs.uni-dortmund.de/~peter/PS07/HR.pdf).)
374
375
376 The rest of these are a bit more advanced, and are also looser suggestions:
377
378 *   *Computational Semantics with Functional Programming*, by Jan van Eijck and Christina Unger, currently $42 on [Amazon](http://www.amazon.com/dp/0521757606). We own this but haven't read it yet. It *looks* like it's doing the same kind of thing this seminar aims to do: exploring how natural language meanings can be understood to be "computed". The text uses Haskell, and is aimed at linguists and philosophers as well as computer scientists. Definitely worth a look.
379 <!--
380 It deals with both denotational meaning (where meaning
381 comes from knowing the conditions of truth in situations), and
382 operational meaning (where meaning is an instruction for performing
383 cognitive action).
384 -->
385
386 *   Another good book covering the same ground as the Hankin book, but
387 more thoroughly, and in a more mathematical style, is *Lambda-Calculus and Combinators:
388 an Introduction*, by J. Roger Hindley and Jonathan P. Seldin, currently $74 hardback / $65 kindle on [Amazon](http://www.amazon.com/dp/0521898854).
389 This book is substantial; and although it doesn't presuppose any specific
390 mathematical background knowledge, it will be a good choice only if you're
391 already comfortable reading advanced math textbooks.
392 If you choose to read both the Hankin book and this book, you'll notice the authors made some different
393 terminological/notational choices. At first, this makes comprehension slightly slower,
394 but in the long run it's helpful because it makes the arbitrariness of those choices more salient.
395
396
397 *   Another good book, covering a bit of the same ground as the Hankin and the Hindley &amp; Seldin, but focusing especially on typed lambda calculi, is *Types and Programming Languages*, by Benjamin Pierce, currently $77 hardback / $68 kindle on [Amazon](http://www.amazon.com/dp/0262162091). This book has many examples in OCaml. It seems to be the standard textbook for CS students learning type theory.
398
399 *   The next two books focus on the formal semantics of typed programming languages, both in the "denotational" form that most closely corresponds to what we mean by semantics, and in the "operational" form very often used in CS. These are: *The Formal Semantics of Programming Languages*, by Glynn Winskel, currently $38 on [Amazon](http://www.amazon.com/dp/0262731037), and *Semantics of Programming Languages*, by Carl Gunter, currently $41 on [Amazon](http://www.amazon.com/dp/0262071436).
400
401
402 ----
403
404 All wikis are supposed to have a [[SandBox]], so this one does too.
405
406 This wiki is powered by [[ikiwiki]].