15-150: Principles of Functional Programming

Lecture 5: Recursion and Structural Induction on Trees

We show how to create some user-defined tree datatypes.

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

Key Concepts

Sample Code

The notes from last lecture are again relevant

As a reminder: When SML evaluates a function application of the form e1 e2, SML does the following in the following order:

  1. Evaluates e1 to a function value f. (In what follows, assume f has formal variable x.)
  2. Evaluates e2 to a value v.
  3. Extends the environment in effect at the time of definition of f with the local binding [v/x].
  4. Evaluates the body of f in the resulting environment
See again the area function in the code for Lecture 2 and see page 4 of the evaluations notes from that day.