Skip to main content
Department of Information Technology

Functional programming

Some programs have a function, these programs are a function!

Functional programming is an approach to declarative programming. The aim is for the programmer to state only the problem, but not a sequence of steps solving it. In functional programming, the programmer does this by defining a (mathematical) function. Consider the problem of the Towers of Hanoi. A stack of n disks (n=6 in the figure) has to be moved disk by disk from tower A to tower C using tower B, so that no disk ever lies on a smaller one. The strategy consists of solving the similar but smaller problem of moving the top-most n-1 disks from A to B using C, moving the largest disk from A to C, and solving the similar, smaller problem of moving n-1 disks from B to C using A. So the function hanoi n, which returns the sequence of moves, invokes the function hanoi (n-1) twice. Except hanoi 0, which returns no moves at all.
Declarative programming is thus very different from imperative programming and object-oriented programming, where a program is basically a sequence of steps.Come and widen your programming-language horizon. Declarative programming is not difficult and often leads to very elegant programs, once you are used to it! The main objective is to learn functional programming, and to see how well it realises the aim of declarative programming. It is successfully used in many industry projects, which makes knowledge of it a useful asset on the job market. Improvements of programming quality and speed by several factors are not uncommon. You also learn when it is wiser to use declarative programming rather than imperative programming or object-oriented programming. Prerequisites: Programming and data structures (imperative or object-oriented), algebra. Goal: To give you a broader view of what programming is. Required for: Functional programming is the first language for DVP and ITP. So many courses refer to it.

Updated  2008-04-04 19:45:08 by Roland Bol.