Geek Rant

All talk and no action

Archive for January 2008

On the Utility of Functional Programming

with 3 comments

I have been using Haskell for about a year now (wow, has it really been that long?), and I think I have arrived at a point that I can talk about how useful it actually is with some level of credibility. It’s a question that comes up very often, mostly among imperative-only programmers and functional neophytes, but even a seasoned Haskell programmer might ask it from time to time.

The Haskell community suffers from a serious problem. There are very few large projects written in Haskell. There are very few libraries. There is very little use of Haskell in industry. There just isn’t much proof out there that Haskell is all that superior for somebody who wants to actually get something done. Before I finally decided to learn Haskell, I had poked around on Google on numerous occasions looking for some sort of evidence that it would be worth it. My conclusion almost every single time was that Haskell is nothing more than an academic language for academic people. I found the small examples amusing, such as the quicksort algorithm expressed as a couple lines of dense symbols and small variable names, but I never found anything significantly larger or more useful. Later, I heard about darcs, a distributed source code management system. It was the first time I had even heard of such a thing, so I decided to give darcs a shot to see if I liked it better than Subversion. I used MacPorts to install it, which usually compiles from source. Installing darcs took an extremely long time since I had to compile GHC first, and once it was installed, it turns out that darcs was, itself, extremely slow as well. This was the first time I had knowingly used anything written in Haskell. I made up my mind. Haskell was very, very slow, and would never be anything worth learning except as a mind exercise. Only a long time later, after I had already learned Haskell, did I learn that it wasn’t Haskell but the darcs “theory of patches” algorithm itself that was so slow.

Over the next couple years, I became more interested in programming language theory, so, inevitably, I became interested in functional programming once again. I had heard that OCaml was very fast, and since it was impure I had the impression that to catch on to it would be more natural for me, an imperative programmer, than a pure language like Haskell. I started through a couple tutorials, but never felt like I was learning anything ground-breaking. The syntax was surely different from what I was used to using, but the thinking process felt too similar. This did not line up with what I had heard about the way functional programming is supposed to open up your mind and whatnot. But weren’t monads supposed to be hard to learn and confusing to use? It didn’t make sense to me that purity was worth anything. I finally gave in. I learned Haskell.

I have gained a lot since then. I learned all kinds of neat stuff, like monads, generic algebraic data types, type classes, functional dependencies, purely functional IO, pattern matching, purity, and types as proofs. To a nonfunctional programmer, this list probably looks like a bunch of gobbledygook, but each of these concepts has expanded my mind. It was difficult, especially having to read academic papers just to feel like I had some notion of what each of these concepts meant at all, but I now have a strong interest in learning more, and there is oh so much more to learn! Functional programming has led me to a wondrous path of discovery.

My programming skills have definitely improved. I am a better programmer in every language I use because of Haskell. I use Haskell most of the time now though. It’s really not that bad. I get a lot done. I feel better about the code I write. I could even write a large application in Haskell without feeling like I am limited in some way. Haskell is, without a doubt, practical for every day use, far more so than any of the imperative language I have come across.

The only problem is that I find myself dissatisfied even with Haskell. I have finally been exposed to the wide open world of programming language theory, and all the numerous flaws of the popular (and unpopular) languages of today. The fun of programming has been stripped away from me because I have read and understood so many papers detailing better ways of doing everything. I no longer want to work on large projects, even in Haskell. I just want to further improve my Haskell skills, make Haskell better, find a better language, or make my own language from scratch.

This is the root of the problem. This is why, I think, there are not so many large Haskell projects out there. It’s just too tempting to make your skills and development environment even better now that you have caught a glimpse of the light. This only leads you farther and farther from reality into academia. It’s a black hole. The Haskell community certainly could write significant applications in Haskell, we just choose not to do so because there are so many opportunities for improvement. It takes a great deal of discipline to focus exclusively on the implementation of a project without being distracted by “what if I …,” “wouldn’t it be neat if …,” and “if only ….” Haskell, while leaps and bounds more enjoyable and productive than any of the imperative languages I know, has made me dissatisfied.

Written by Jake

January 12, 2008 at 8:14 pm