Part II: Programming Languages
This page contains all the information specific to Part II.
Schedule
This part will cover the semantics of programming languages in theory and in practice.
- We start by introducing the untyped lambda calculus as an alternative model of computation, exploring its (simple) abstract syntax, and defining and implementing some of its (very simple) semantics.
- We will then look towards a much more earthly imperative language—IMP—and its semantics, which we’ll animate as they are, and perhaps extend.
- We will think about the logical and mathematical tools we need to reason about a language’s semantics, and a program’s correctness.
- We will define and animate the semantics of a small stack machine, and define a translation from IMP to its language. We will implement this translation as a compiler.
Week | Lecture 1 | Lecture 2 | Problem Sheet | Lecture 3 |
---|---|---|---|---|
4 | Introduction - Part 1: Why? (notes) |
Untyped $\lambda$-calculus - Part 1: $\lambda$-terms and $\beta$-reduction (notes); - Part 2: Live coding: $\lambda$-terms and $\beta$-reduction (notes) |
Evaluating $\lambda$-terms | Computing with $\lambda$: CBV, CBN, Church encodings - Part 1: Evaluation strategies (notes); - Part 2: Live coding: CBV (small-step); - Part 3: Church encodings (notes) |
5 | Break | Break | Reasoning about $\lambda$-terms | Break |
8 | IMP/While (notes) - Part 1: Introduction and syntax; - Part 2: Semantics of expressions |
Semantics of IMP - Part 1: Structural Operational Semantics (notes); - Part 2: Natural Semantics (notes) |
Reasoning about semantics and Interpreting IMP programs | Reasoning on IMP and its semantics - Part 1: Structural operational semantics agree with natural semantics (notes); - Part 2: Natural semantics agree with structural operational semantics (notes); - Part 3: Why do we have both, then? (notes) |
9 | The Abstract Machine - Part 1: Interpreters vs Compilers (notes); - Part 2: The Abstract Machine (notes) |
Compiling IMP programs to the Abstract Machine - Part 1: Compiling IMP to AM (notes); - Part 2: (Optional) Some Less Abstract Machines (notes) |
Compiling IMP programs to the Abstract Machine | Reasoning about compilation - Part 1: Proving Compilation Correct (notes) |
10 | (Unassessed) Extending IMP: Procedures - Part 1: Motivation and syntax (notes); - Part 2: Semantics of Blocks and Local Variables (notes) |
(Unassessed) Extending IMP: Procedures (II) | - | - |
You will know enough to start the problem sheet for a given Week after listening to the first two lectures of the same Week. The problem sheet and Lecture 3 of a given Week will often be designed to be looked at together.
In the above table, a lecture or part being marked as (Optional) means that it is not necessary to have watched it to pass the unit or get a low first. Some top-range marks might assume some exposure to the material.
A lecture or part being marked as (Unassessed) means that even top-range marks won’t be touching the concepts the lecture or part introduces.
Problem Sheets
The problem sheets will appear here, along with Haskell templates, when ready. They will also be uploaded to the Files tab of the General channel in the COMS20007 Team.
Week | Sheet | Starter Code | Sample Answers | Sample Code |
---|---|---|---|---|
4 | Problem sheet | Starter Code | Solutions | Final Code |
5 | Problem sheet | - | Solutions | - |
8 | Problem sheet | Starter Code | Solutions | Final Code |
9 | Continue on sheet 3, get started on sheet 4 | |||
10 | Problem sheet | Starter Code + Abstract Machine | Solutions | Final Code |
For the programming tasks, we will assume a barebones Haskell that gives you access to a reasonable version of Cabal.
We provide a Vagrantfile, for use with Vagrant and VirtualBox. The recipe uses ghcup to set up Haskell, Cabal, as well as Alex and Happy, which I will sometimes use for writing lexers and parser.
We’ve also prepared a docker container, tested to work with both docker
and
podman
. You can run docker run fdupress/coms20007lab
, with appropriate
options to mount the problem files and start the command you want. The
container uses an Alpine base image and will lack creature comforts even if you
put some effort into expanding it. The idea here is to use the container as a
thin wrapper around Haskell tools, rather than a full-blown system in which
you’ll do your work.
Materials
We will refer to the following two texts:
- Benjamin Pierce’s Types and Programming Languages. (We will use only Chapters 5 and 6, but Chapters 1 to 4 are a generally useful read.) We refer to this as “Pierce”.
- Nielson and Nielson’s Semantics with Applications: A Formal Introduction. (The plan calls only for Chapters 1 to 3, but we might foray into Chapters 5 and 6 if time and biology cooperate.) We refer to this as “Nielsons”.
In the following table, Lectures are indexed as Week.Lecture (not part) to avoid ambiguities in case of interruptions in the schedule.
Lecture | Additional recommended reading |
---|---|
4.1 | Pierce (Ch. 1-2) |
4.2 | Pierce (Ch. 5) |
4.3 | Pierce (Ch 3, 5) |
5 | - |
8.1 | Nielsons (Ch. 1) |
8.2 | Nielsons (Ch. 2.1, 2.2) |
8.3 | Nielsons (Ch. 2.3) |
9.1 | Nielsons (Ch. 3.1) |
9.2 | Nielsons (Ch. 3.2) |
9.3 | Nielsons (Ch. 3.3-3.4) |
10.1 | Nielsons (Ch. 2.5) |
10.2 | Nielsons (Ch. 2.5) |