15-150: Principles of Functional Programming

Lecture 5: Trees

In this lecture, we introduced trees in SML. We saw they could be represented fairly compactly using a datatype declaration, which let us define trees as being made up of two constructors, Empty and Node.

We then learned about tree traversals, and used it to prove that summing a list and summing a tree were equivalent, when inorder traversal was used to transform from a tree to a list.

We then saw that datatypes gave rise to algebraic datatypes, which are types that allow us a great deal of versatility in specifying our problems. We used datatypes to define an order type, which allowed us more specificity in specifying the output of a comparison function, while generally being safer than using bare strings.


Proof of totality of the depth function discussed in lecture