15-150: Principles of Functional Programming

Lecture 10: Higher-Order Functions

We defined what it means to curry a function and how to write curried functions in SML.

(If you have forgotten about closures, please revisit Lecture 2.)

We discussed higher-order functions. A function that takes another function as an argument is classified as a higher-order function, as are functions that return higher-order functions. (Some authors broaden the definition to also include any function that returns a first-order function. We intentionally do not do that, so that currying or uncurrying a function does not change its order.)

We discussed passing functions as arguments, returning functions as values, and mapping functions over recursive data structures. Key to understanding functions as first class values is understanding the lexical scoping rules.

We discussed several important higher-order functions on lists, including filter, map, foldl, and foldr.

Key Concepts

Sample Code

Some Notes on Higher-Order Functions

Here is some extra material about folding:   How to Fold, along with code.

(today's lecture was a blackboard lecture, so no slides)