Friday, 5 October 2012

Functional Programming

Functional programming(FP) is one of the programming paradigm, paradigm means which describes various concepts and ideas. Functional programming was the new way to abstract and compose the structure and to avoid mutation. Functions are the basic structures that leads to higher procedural abstractions. Functions in FP are first class citizens that can be
:: defined anywhere inside or outside the functions
:: can be passed as arguments

Popular functional programming languages are
:: Lisp
:: Scala
:: Scheme
:: Racket
:: Clojure
:: Small Talk
:: Ruby

Functions are the powerful ways of abstracting operations and lower order formulas in order to modularize each part of programming construct and segregate to form a higher order construct using basic functions. Functions that  can manipulate functions are known as higher order functions. These powerful way of abstraction will increase the expressive power of our language.

Glueing  functions together

Glue enables simple functions to be glued together to make more complex ones. It can be illustrated with a simple list- processing problem - adding up the elements of a list. We define lists by

listof X ::= nil | cons X (listof X)

which means that a list of Xs (whatever X is) is either nil, representing a list
with no elements, or it is a cons of an X and another list of Xs. A cons represents
a list whose first element is the X and whose second and subsequent elements
are the elements of the other list of Xs.
[]            means     nil
[1]          means     cons 1 nil
[1,2,3]    means     cons 1 (cons 2 (cons 3 nil))

Our ability to decompose a problem into parts depends directly on our ability to glue solutions together. To assist modular programming, a language must provide good glue.

Functional programming languages provide two new kinds of glue - higher-order
functions and lazy evaluation. Using these glues one can modularise programs
in new and exciting ways, and as small snippets explained earlier.

No comments:

Post a Comment