# Introduction to Functional Programming (1996/7)

John Harrison

This year's (1997/8) course is here. The present page has more material.

Computer Science Tripos, Part II (General) and Diploma in Computer Science
Twelve lectures, beginning on Fri 16th Jan 1997, ending on Tue 11th Feb 1997
Tuesday, Thursday & Friday at 12:00 in the Hopkinson Lecture Room

## Lecture Notes

Entire notes (160 pages): DVI, Postscript, PDF

## Copies of slides

1. Introduction and Overview: Colour Postscript
2. Lambda calculus as a formal system: Colour Postscript
3. Lambda calculus as a programming language: Colour Postscript
4. Types: Colour Postscript
5. ML: Colour Postscript
6. Details of ML: Colour Postscript
7. Proving programs correct: Colour Postscript
8. Effective ML: Colour Postscript
9. ML examples I: Symbolic differentiation: Colour Postscript
10. ML examples II: Recursive descent parsing: Colour Postscript
11. ML examples III: Exact real arithmetic: Colour Postscript
12. ML examples IV: Prolog and theorem proving: Colour Postscript
Additional material is available from those who have taught the course in previous years: Mike Gordon and Andy Gordon. The theoretical part of the course is also covered by lecture notes from Larry Paulson.

## Syllabus

This describes roughly how the course was taught over 12 lectures, each of slightly less than an hour. Only what was actually taught will be examinable.
1. Introduction and Overview Functional and imperative programming: contrast, pros and cons. General structure of the course: how lambda calculus turns out to be a general programming language. Lambda notation: how it clarifies variable binding and provides a general analysis of mathematical notation. Currying. Russell's paradox.
2. Lambda calculus as a formal system Free and bound variables. Substitution. Conversion rules. Lambda equality. Extensionality. Reduction and reduction strategies. The Church-Rosser theorem: statement and consequences. Combinators.
3. Lambda calculus as a programming language Computability background; Turing completeness (no proof). Representing data and basic operations: truth values, pairs and tuples, natural numbers. The predecessor operation. Writing recursive functions: fixed point combinators. Let expressions. Lambda calculus as a declarative language.
4. Types Why types? Answers from programming and logic. Simply typed lambda calculus. Church and Curry typing. Let polymorphism. Most general types and Milner's algorithm. Strong normalization (no proof), and its negative consequences for Turing completeness. Adding a recursion operator.
5. ML ML as typed lambda calculus with eager evaluation. Details of evaluation strategy. The conditional. The ML family. Practicalities of interacting with ML. Writing functions. Bindings and declarations. Recursive and polymorphic functions. Comparison of functions.
6. Details of ML More about interaction with ML. Loading from files. Comments. Basic data types: unit, booleans, numbers and strings. Built-in operations. Concrete syntax and infixes. More examples. Recursive types and pattern matching. Examples: lists and recursive functions on lists.
7. Proving programs correct The correctness problem. Testing and verification. The limits of verification. Functional programs as mathematical objects. Examples of program proofs: exponential, GCD, append and reverse.
8. Effective ML Using standard combinators. List iteration and other useful combinators; examples. Tail recursion and accumulators; why tail recursion is more efficient. Forcing evaluation. Minimizing consing. More efficient reversal. Use of `as'. Imperative features: exceptions, references, arrays and sequencing. Imperative features and types; the value restriction.
9. ML examples I: symbolic differentiation Symbolic computation. Data representation. Operator precedence. Association lists. Prettyprinting expressions. Installing the printer. Differentiation. Simplification. The problem of the `right' simplification.
10. ML examples II: recursive descent parsing Grammars and the parsing problem. Fixing ambiguity. Recursive descent. Parsers in ML. Parser combinators; examples. Lexical analysis using the same techniques. A parser for terms. Automating precedence parsing. Avoiding backtracking. Comparison with other techniques.
11. ML examples III: exact real arithmetic Real numbers and finite representations. Real numbers as programs or functions. Our representation of reals. Arbitrary precision integers. Injecting integers into the reals. Negation and absolute value. Addition; the importance of rounding division. Multiplication and division by integers. General multiplication. Inverse and division. Ordering and equality. Testing. Avoiding reevaluation through memo functions.
12. ML examples IV: Prolog and theorem proving Prolog terms. Case-sensitive lexing. Parsing and printing, including list syntax. Unification. Backtracking search. Prolog examples. Prolog-style theorem proving. Manipulating formulas; negation normal form. Basic prover; the use of continuations. Examples: Pelletier problems and whodunit.

## Papers and documentation online

Here are some useful books, papers and tutorials online. They might save a trip to the library.

## Online ML resources

This is a collection of other Web links that are relevant to the material we cover in the second part of the course.