8.7 Chapter Summary

The concepts of partial function application and currying lead to a modular style of functional programming when applied as and with other higher-order functions (HOFs). Partial function application refers to the concept that if a function— which accepts at least one parameter—is invoked with only an argument for its first parameter (i.e., partially applied), it returns a new function accepting the arguments for the remaining parameters; the new function, when invoked with arguments for those parameters, yields the same result as would have been returned had the original function been invoked with arguments for all of its parameters (i.e., a complete function application). Currying refers to converting an n-ary function into one that accepts only one argument and returns a function that also accepts only one argument and returns a function that accepts only one argument, and so on. Function currying helps us achieve the same end as partial function application (i.e., invoking a function with arguments for only a prefix of its parameters) in a transparent manner—that is, without having to call a function such as papply1 every time we desire to do so. Thus, while the invocation of a curried function might appear as if it is being partially applied, it is not because every curried function is a unary function.

Higher-order functions support the capture and reuse of a pattern of recursion or, more generally, a pattern of control. (The concept of programming abstractions in this manner is explored further in Section 13.6.) Curried HOFs provide the glue that enables programmers to compose reusable atomic functions together in creative ways. (Lazy evaluation supports gluing whole programs together and is the topic of Section 12.5.) The resulting functions can be used in concert to craft a malleable/reconfigurable program. What results is a general set of (reusable) tools resembling an API rather than a monolithic program. This style of modular programming makes programs easier to debug, maintain, and reuse (Hughes 1989).

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

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