CS358: Programming Language Foundations


Instructors: Marco Patrignani

General course information:

This course presents the foundations of programming languages: the lambda calculus.

It also describes advanced type systems applied to the lambda calculus: polymorphism (System F), recursive types, heap typing and non-interference.

Finally, this course delves deeply in the meaning of semantic typing and in reasoning about programs using logical relations.

Students will learn how to formalise languages and why that is important, how to reason about different and complex language constructs through advanced methods. Students will come to know all basic typing constructs as well as several advanced ones as found in many modern languages.

For any question, please contact Marco Patrignani (see mail here).

Piazza and Gradescope links:

Piazza: https://piazza.com/stanford/winter2020/cs358/

Gradescope: https://www.gradescope.com/courses/60070  (find the code in piazza)

Prerequisites and interests:

Interest in formal languages and formal techniques is important.

Having attended cs143, or cs242 (2018 onwards edition) or cs350 will provide a bit of background.

Auditing is welcome.

Students that show interest in these topics and want to further their knowledge are welcome to contact the instructor.

Location and Time Slots:

Time slot:

   T-TH, 10:30-11:50


   Thornton 209

Office hours:

    Preferably Friday afternoon 15 - 17, other slots can be opened if need be.

    Please drop an email ahead of time if you plan to come.

Teaching Assistant:


Evaluation and Grading:

The course has a number of intermediate assignments and a final exam.

Assignments will help a student consolidate the skills necessary to understand this course as well as prepare them for the final exam. You can collaborate on solutions to exercises together, but you must write your solution individually, in your own words.

        Assignments will be available typically one week in advance before they are due.

        Typically, they are due on Wednesday, and they’ll be available the Wednesday before.

        Please check them out before class and report possible elements of confusion.

  1. -Assignment 1 [ ass1.pdf ] due date:  19th Jan

  2. -Assignment 2 [ ass2.pdf ] due date:  29th Jan

  3. -Assignment 3 [ ass3.pdf ] due date:  5th Feb

  4. -Assignment 4 [ ass4.pdf ] due date:  12th Feb

  5. -Assignment 5 [ ass5.pdf ] due date:  19th Feb

  6. -Assignment 6 [ ass6.pdf ] due date:  26th Feb

  7. -Assignment 7 [ ass7.pdf ] due date:  4th Mar

       Assignment turn-in must happen through Gradescope (see link above).

Final exam: the final exam is a take-home set of exercises analogous to those presented in the assignments. The same collaboration policy as the assignments applies to the exam as well. 

  1. -Exam [ exam.pdf ] due date: 13th Mar

    Final exam turn-in must happen through Gradescope (see link above).


70% assignments

30% final exam

Course materials:

Courses on foundations on PL are widespread, thus there are many textbooks and lecture notes out there.

The instructor recommends the following in order to integrate notes taken during class. Please note that the course will indeed follow Dreyer’s notes and TAPL.

  1. -Derek Dreyer’s lecture notes [ pdf ]

  2. -Benjamin Pierce’s TAPL [ amazon ]

  3. -Marco Vassena’s lectures on IFC [ pdf ]

High-level Syllabus Outline:

The course is divided in the following parts:

  1. -Part 0: Typesetting PL notions in LaTeX
    In order to typeset PL notions in LaTeX akin to those we see in class, please check out this document [
    .tex ] and the related commands file [ .tex ], it should compile to this document [ .pdf ].

  1. -Part 1: the lambda calculus.
    Here we’ll see the untyped and the simply-typed lambda calculus, different forms of operational semantics: structural and contextual, types such as pairs, products, properties such as progress, preservation, strong normalisation, semantic type soundness.

  2. -Part 2: System F
    Here we’ll see System F, the polymorphic lambda calculus with universal and existential types, how to encode them in a semantic model of type soundness, how to scale the previous properties to this complex setting and how to reason about Parametricity.

  3. -Part 3: Recursion
    Here we’ll see how to extend the language with recursive (or \mu) types, their different forms, the semantic model for (now) possibly-diverging computation in the form of Kripke Logical Relations.

  4. -Part 4: Mutable state
    Here we’ll extend the language with a state, so a heap with operations for allocation, reading and writing to it, changing the computation from pure to impure, we will study the semantic model for stateful computation.

  5. -Part 5: Program equivalence
    Here we’ll learn how to formalise and reason about the semantics of programs and how to tell when they behave the same, we will see what properties to encode as equivalences and how to develop a semantic model for program equivalence.

  6. -Part 6: Advanced Type Systems
    Here we’ll study advanced type systems such as linear types, security types for secure information flow and non-interference, robust-safety typing, multilanguage semantics.

Class (and Lectures) Outline:

        Please note that this is tentative and precise class contents can vary slightly

The whiteboard shots of each lecture are collected on a google drive folder whose link is on piazza.

7th January

    ULC syntax, SOS semantics, small step CBV, CBN

9th January

    ULC SOS big step, contextual semantics (COS), equivalence of SOS and COS

14th January

    equivalence of SOS and COS (cont’d)

    STLC sums, pairs, encoding if-then-else, typing

16th January

    STLC progress and preservation, strong normalisation, logical relation (LR), semantic typing, fundamental prop

21st January

    STLC compatibility lemmas.

23rd January

    -- Instructor away. --  (no class)

28th January

    SF: universal types syntax, typing, semantics, existential types & records.

30th January

    SF new logical relation & compatibility lemmas

4th February

    Free theorems

6th February

    Assertions, type safety despite untypability Using the value relation for existentials

11th February

    Mu types, iso and equi recursive types, step-indexed LR for mu types

13th February

    References, usage and typing, Kripke worlds

18th February

    Kripke worlds


20th February

    LR with references

25th February

    Advanced type systems: Non interference pt1

    This lecture will be held by Marco Vassena

27th February

    Advanced type systems: Non interference pt2

    This lecture will be held by Marco Vassena

3rd March

    Contextual equivalence (CEQ), program contexts

5th March

    Binary logical relation for CEQ and for parametricity, representation independence

10th March

    Advanced type systems: speculative semantics and spectre

12th March

    Advanced type systems: linear typing