15-150: Principles of Functional Programming

Lecture 11: Higher-Order Functions (continued)

We continued our discussion of higher-order functions:

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

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

We discussed combinators. Combinators are higher-order functions that lift operations from a type to functions with values in that type. Combinators may be defined using the pointwise principle. Currying makes this easy in SML.

We 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.

Finally, we considered mapping and filtering over trees.

Key Concepts

Sample Code

Code generated during the live-coding session in the 3pm lecture

More notes on higher-order functions

See also again the notes from last time on higher order functions, particularly for the generalization to trees.