Chapter 7
Further Generalization



Function composition

It is easy for students to confuse function application and function composition, especially when a composition is applied to an argument. Again, it seems to be a point which only sinks in after the mistake has been made a few times.

Functions as results

In many imperative languages (Pascal, Modula-3, etc.) it is possible to define functions like map and filter. What limits their use is that it is not possible to build the functions to be mapped or filtered at run time, as functions cannot be the results of other functions. The functions to be mapped etc. must be functions declared in the program, and so defined `in advance', as it were.

Partial application

I find that the rule of cancellation is useful in explaining what happens in partial application. There is a small sleight of hand here in the application of polymorphic functions, in that some specialisation may take place via unification; this is handled in Chapter 8.

The explanation on pp 176-177 makes clear the exact nature of what has gone before; it is worth revisiting your own examples also here.

Making the index

The example of making the index (Section 7.6) is a basis for further discussion:

An advantage of the design of the program is that components can easily be added, modified or removed from the composition, without affecting the remainder of the system.

Understanding programs

Now is a good point to remind students of Appendix D, which looks at an unfamiliar function definition from a number of points of view.

Next Up

Written 18 May 1995.