Abstraction of Functional programming


As shown by Google trend, the functional programming is becoming popular again in recent years. Functional programming is not a brand new idea. It’s concept is first used in Lisp since 1950s. And it is popular again in the big data era when the parallel programming and scalability is a must in the program developments.

So, what is exactly is functional programming? When I first heard of functional programming, I was interpreting it as to write a function and call it like every programming language doing. It is true and false. In programming languages, the most basic entry is expression, like:

x = x + 1;

In this expression, x is added by 1. We can view it as Elementary mathematics. To use the functional thinking, we define an add 1 function:

int add1(int x){
  return x + 1;

What’s the different? In define the function add1, we now have the ability to reuse it in other places, we now can do the same operations to variable y and z. This is the abstraction of add 1 operation. However, if we want to add 1 to a double type variable, we need to define another function (in Java we can use the same function name):

double add1(double x){
  return x + 1;

We have to write the same code once again. Thus, we can not easily “scale” to many more data types. We can abstract it further:

T add1(T x){
  return x + 1;

This is the add 1 operation on type T. We are able to repeat the same add 1 operation only if the type T support + operation. We can use the power of “abstraction” to abstract many operations. One of the successor of functional programming language, Haskell, has built in support of map, reduce, filter e.g. functions to iterate a list of objects, thus no long need to use for expression. There are many benefit in design such an interface. Locality aware scheduling then can be enabled in map reduce functions without giving too much details to the application.

To this point, we can view functional programming as an high-level abstraction of problem/operations or a better interface design philosophy.

The philosophy of functional programming including: immutable data, first class functions,declarative Programming, pipeline, Lambda Expressions.