15-150: Principles of Functional Programming

Lecture 18: Representation Invariants (Red/Black Trees)

We demonstrated a complicated representation invariant using Red/Black Trees. The main lesson is to understand the subtle interactions of invariants, data structures, and reliable code production. In order to write code satisfying a strong invariant, it is useful to proceed in stages. Each stage satisfies a simple invariant, and is provably correct. Together the stages satisfy the strong invariant.

Key Concepts

Suggested Reading in Programming in Standard ML:

This chapter covers the code and ideas of today's lecture closely.
On older online version of that chapter may still be accessible here:

Sample Code

Slides from noon lecture

Slides from 3pm lecture

Live Coding from 3pm lecture