Home > Articles > Home & Office Computing > Mac OS X

  • Print
  • + Share This
Like this article? We recommend

Higher Order Functions

Object-oriented programming was adopted by the industry as a logical development from structured (procedural) programming. In academia, as well as in some high-reliability development environments, another approach was popular: Functional programming is based on the idea that a program should be composed from mathematical functions — which, unlike procedures, doesn't modify global state or have any side effects.

In a pure functional language, everything is a function; just as, in a pure object-oriented language like Smalltalk, everything is an object. In Haskell, for example, a constant is really a function that takes no input and returns a value. Because everything is a function, the things that are arguments to functions are also functions.

This homogeneity makes possible some very useful programming patterns. A higher-order function is a function that takes functions as arguments. The canonical example would be a map function, which takes a function and a collection as arguments and returns another collection generated by applying the function to every argument.

This capability is very simple to implement and to use in a pure functional language. It's also incredibly powerful. The map-reduce model employed by Google is trivial in any functional language. In a concurrent functional language like Erlang, you can implement map reduction in four lines of code. It would be very nice to be able to borrow this programming model for object-oriented code.

  • + Share This
  • 🔖 Save To Your Account