Bilkent University, Comp. Eng. Dept., Functional Programming Society

The primary aim of this site is to improve people's knowledge and encourage the use of functional programming languages: Clojure, Common Lisp, Erlang, Haskell, Scala, Scheme, e.t.c. (For further information and contributing see our Manifesto.) Project development is led by Bilkent University Computer Engineering Department students, but the site is open to contributions from others as well. (See About Us for further information.)

For discussion on functional programming languages in Turkish, we invite everyone to join the Bilgi University Computer Science Department cs-lisp mailing list. Despite the fact that the mailing list has 'lisp' in its name, discussion related to any functional programming language is welcome. Moreover, the experience of hundreds of previously registered users is a significant bonus.

Why Functional Programming Matters

Functional programming languages bring a different perspective to programming compared to imperative languages like C or Java. Consider the statement x = x + 1. This is one of the most intuitive aspects of imperative programming; we tend to manipulate and change the values of variables. However, in functional programming, once you set the value of a variable it cannot be changed (it is immutable). Or, put more simply, you cannot change the value of x to x + 1. x will remain x untill the end of the execution of the program. Moreover, there are no statements, no assignments and no flow of control. In other words, the major source of bugs are thus eliminated.

The power of functional languages lies in higher order functions, powerful use of abstractions and consequently improved modularity. These concepts lead to code that is concise, expressive and understandable with respect to their imperative counterparts. Use of abstraction is somewhat advanced, so let's take a look at what we mean by higher order functions and their impact on modularity. We will continue to keep our examples as simple as possible. Here are some functions written in Haskell:

sumList       = foldr (+) 0
multiplyList  = foldr (*) 1
appendList xs = foldr (:) xs

As you may have guessed, the first function sums a list, the next function multiplies a list and the last function prepends a given list to another. See how the foldr function is used to express different purposes. The result of using a higher order function is clear; the written code is more concise, simple and expressive. You would do this by using a loop and variables in a conventional imperative language which is much more difficult to read and debug.

Another powerful, disputed and yet to be exploited tool for modularity is lazy evaluation, which simply means don't evaluate until you need it. For instance, consider these infinite data structures created using lazy evaluation techniques:

-- Infinite sequence of Fibonacci numbers in Haskell.
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)

-- Infinite sequence of positive even numbers in Haskell.
[0,2..]                                -- With list representations, easy way.
evenPosInts = 0 : map (+2) evenPosInts -- Functional recursive way.

;; Infinite sequence of positive even numbers in Clojure.
(iterate #(+ 2 %) 0)

/* Filtering out odd numbers from a Stream of integers in Scala. */
def from(n: Int): Stream[Int] = Stream.cons(n, from(n + 1))
from(2) filter { _ % 2 == 0 }


Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License