15-150: Principles of Functional Programming

Lecture 5: Trees

This lecture, we introduced the type of binary trees in SML, which make use of SML's powerful datatypes language feature.

We explored the different kind of traversals on trees, and found that trees admitted a new principle of structural induction due to having a different form than that of lists. We then did a structural induction proof on trees, where we discovered the necessity of totality citations due to stepping through theorem values.

To finish off the lecture, we discussed the power of having custom-built datatypes that fit a problem exactly. We talked about the importance of making illegal states unrepresentable and defining one's problem domain specifically.

-->

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 order with constant constructors LESS, EQUAL, GREATER.
We made up some of our own datatypes, including a datatype to model the extended integers, two different tree datatypes, and a datatype for operator-operand trees.

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

Key Concepts

Sample Code

The notes from last lecture are also again relevant

Proof of totality of the depth function discussed in lecture

Slides