15-150: Principles of Functional Programming

Lecture 11: Higher-Order Functions II

We continued our discussion of higher-order functions:

Recall that functions which take other functions as input are classified as higher-order functions (as are functions that return higher-order functions).

We saw higher-order list functions last time. We also saw function composition, given by SML's infix operator o.

We continued our discussion of higher-order functions, expanding it from mapping and folding over lists to mapping and folding over trees (and arbitrary datatypes more generally).

We then discussed staging. Staging takes advantage of the nested lambda form of a curried function to move parts of a computation close to the place where the arguments required for the computation appear. This can save computation time in a function that can do some of its work as soon as it sees its first argument, for instance. When called several times with the same first argument and different second arguments, the function can reuse the results of these early partial computations, since they are available in the environment part of the closure associated with the function that expects the second argument.

Key Concepts

Sample Code

More notes on higher-order functions

See again the notes from last time on higher order functions, particularly for the generalization to trees.
See as well again the notes discussing generalizations of fold.

Lecture Slides

Lecture Slides with every build, use "slideshow" option in your pdf viewer. Lecture Slides compact.