15-150: Principles of Functional Programming

Lecture 4: Structural Induction and Tail Recursion

Today we learned about the benefits of pattern matching over conditionals for the purpose of inspecting data. We learned about the parse, don't validate paradigm of deconstructing data based on its form, not based on validating the data with otherwise informationless predicates.

We also introduced structural induction on lists, which is a form of induction similar to that over the natural numbers, except extended so that it can be used on SML lists. It behaves similarly, except that instead of inducting over numbers, it is inducting over all the kinds of lists that can be formed by the simple recursive definition of a list.

We then learned about the concept of tail recursion, which is when a function makes only one recursive call to itself. This can help in the efficiency and runtime of some functions, and we wrote some examples of tail-recursive functions, as well as seeing why a non tail-recursive implementation of the length function would otherwise take up a large amount of memory.


Some Notes on Structural Induction

(These notes also discuss two concepts that we have not yet discussed: datatype declarations and structural induction over trees; we will see these in the next lecture.)

Proof of an extensional equivalence for two implementations of list reversal