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.
- 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
SML does the following in the following order:
See again the area function in the code for Lecture 2.
- 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