Beginning Functional Programming

Warning: Geekspeak ahead.

I’ve been wanting to learn a functional programming (FP) language for quite a while now.

Ruby being my current fav programming language while also being malleable to FP, I thought I will dabble with some FP in Ruby. But that was not to be. While Ruby does have some basic features like closures that are necessary for FP (although it does not boast of a a lot of clarity), one has to go through a lot of hooplas to achieve immutability — the language offers no assistance here. The following video provides a good overview of what it takes to do FP using Ruby: Better Ruby through Functional Programming by Dean Wampler.

With Ruby out, I now needed a language that embraced FP wholeheartedly. And there is no dearth of choices here; see the Functional Languages category on Wikipedia. I decided to narrow down the list by picking up the more popular and/or adopted languages. This left me with Clojure, Common Lisp, Erlang, F Sharp, Haskell and Scala (but many don’t seem to consider Scala to be truly functional). That’s still too many languages. But the list is small enough that I could learn enough about each of these languages to be able to pick one that I want to learn right now.

Clojure: Lisp dialect, dynamically typed, runs on JVM (and embraces it; implying that any Java library can be used with Clojure with little extra effort), great community. Moreover, it is embraced by my company (one of our very important backend platforms is written mostly in Clojure). More on Clojure later.

Common Lisp: The oldest of them all, dynamically typed, really cool. But too many parens for my liking!

Erlang: Runs on its own rock solid concurrent runtime system, offers distributed concurrency for free, dynamically typed, allows hot swapping and…

Meanwhile, back at Ericsson, some Erlang-based products that were already in progress when the “ban” went into effect came to market, including the AXD 301, an ATM switch with 99.9999999 percent reliability (9 nines, or 31 ms. downtime a year!), which has captured 11% of the world market. The AXD 301 system includes 1.7 million lines of Erlang: This isn’t just some academic language.

(from: Erlang in; emphasis mine.)

F Sharp: Runs on the CLR (.NET Framework).

Haskell: Pure FP language, static typing.

Scala: Runs on JVM, static typing. Very complicated type system, from what I hear.

The above is obviously not a very thorough overview of the languages. It was not my intention to develop an overview at all; I just gathered enough information to be able to make a decision.

I like dynamic typing, working on Linux. My company’s main platform is the JVM. I mostly write Information Retrieval (IR) software and a lot of IR libraries are in Java. Clojure!

But I also like Erlang. I’ll get to it after I have tamed Clojure. And I also want to learn R programming language so that I can implement statistical algorithms with ease.

But what’s the point of this blog post? Nothing. I plan to blog a bit about FP in general and Clojure in particular and thought that it would be nice to provide some context. Also, I wanted to document at least part of the decision making process I have been through for picking up Clojure.

Tags: ,

7 Responses to “Beginning Functional Programming”

  1. Arun Vijayan says:

    For me, FP is pretty hard to understand. However, I clearly see the advantages of it. All the best to you.

    I was (once) very much enthu about learning Haskel. Guess sometime later :-)

    But please share the experiences — I love comparisons as I am not very loyal to any language or technology. Will switch for productivity :-)

  2. Ashok says:

    Go for scala ! :) Its hybrid and best of both the worlds. Pattern Matching is one feature tat counted me in.

    If you really want to learn a lot about FP then Haskell is the way to go. But i’m yet to hear any real world system based on Haskell (May be my ignorance ).

    Clojure has some nice data struts . If you like/from lisp dialect, you are choice is correct :)

  3. Ashok says:

    Yes, as arun said, Share the experience ;)

  4. kopos says:

    I’ve tried Erlang and found it pretty neat. The code is pretty understandable once you are able to wrap your head around the language’s idiosyncrasies. Though we have nothing in production I am really looking forward to pushing Mochiweb for one of our production environments.

    Looking forward to hearing more about your Clojure experiences.

  5. jneira says:

    I choosed clojure too because it seems beautiful and straightforward and it is completely different from java but you can use all this ugly code
    Haskell is beautiful too but in a kind of complex beauty.
    You can take a look to my delicious clojure tag to get links…

  6. [...] few months ago, I had mentioned that I was planning to learn a Functional Programming language. In that blog post I listed out the [...]

  7. gene t says:

    To complete the list of FP languages, you might look at OCaml and scheme