# 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

- trees defined recursively
- datatype declaration of trees
- correspondence between recursive datatype, recursive function
clauses, and proof by structural induction

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

- Evaluates
`e1` to a function value `f`.
(In what follows, assume `f` has formal variable `x`.)
- Evaluates
`e2` to a value `v`.
- Extends
*the environment in effect at the time of definition
of *`f` with the local binding `[v/x]`.
- 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.