8.5 Analysis

Higher-order functions capture common, typically recursive, programming patterns as functions. When HOFs are curried, they can be used to automatically define atomic functions—rendering the HOFs more powerful. Curried HOFs help programmers define functions in a modular, succinct, and easily modifiable/reconfigurable fashion. They provide the glue that enables these atomic functions to be combined to construct more complex functions, as the examples in the prior section demonstrate. The use of curried HOFs lifts us to a higher-order style of functional programming—the third tier of functional programming in Figure 5.10. In this style of programming, programs are composed of a series of concise function definitions that are defined through the application of (curried) HOFs (e.g., map; functional composition: o in ML and . in Haskell; and foldl/foldr). For instance, in our ML definition of string2int, we use foldl, explode, and char2int. With this approach, programming becomes essentially the process of creating composable building blocks and combining them like LEGO® bricks in creative ways to solve a problem. The resulting programs are more concise, modular, and easily reconfigurable than programs where each individual function is defined literally (i.e., hardcoded).

The challenge and creativity in this style of programming require determining the appropriate level of granularity of the atomic functions, figuring out how to automatically define them using (built-in) HOFs, and then combining them using other HOFs into a program so that they work in concert to solve the problem at hand. This style of programming resembles building a library or API more than an application program. The focus is more on identifying, developing, and using the appropriate higher-order abstractions than on solving the target problem. Once the abstractions and essential elements have crystallized, solving the problem at hand is an afterthought. The pay-off, of course, is that the resulting abstractions can be reused in different arrangements in new programs to solve future problems. Lastly, encapsulating patterns of recursion in curried HOFs and applying them in program is a step toward bottom-up programming. Instead of writing an all-encompassing program, using a bottom-up style of programming involves building a language with abstract operators and then using that language to write a concise program (Graham 1993, p. 4).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.128.145