15-150: Principles of Functional Programming

Lecture 5: Datatypes, Recursion and Structural Induction on Trees

We introduced datatype declarations as a form of abstraction designed to relieve a programmer from the burden of keeping track of low-level hacking conventions.
We considered the predefined datatype int option with constant constructor NONE and non-constant constructor SOME, which takes an i : int to construct SOME i : int option. We made up some of our own datatypes, including a type to model colors, multiple return types, and a binary tree type.

We showed how to prove theorems about trees using structural induction.

Key Concepts

Sample Code

The notes from last lecture are also again relevant

Slides from Lecture

Proof of totality of the depth function discussed in lecture