The Paper I Love

I recently presented a talk at the Papers We Love - Winnipeg Chapter meetup. The paper which was the subject of my presentation (and the subject of my affections) was Why Functional Programming Matters, by John Hughes. If that name sounds familiar, hopefully you are not thinking about the prolific film writer and director from the 80’s and 90’s. The former is well known for such cult classics as “Ferris Bueller’s Day Off” and “The Breakfast Club”. The latter is well known for his functional programming street cred.

Professor John Hughes, whose writing I love, is the progenitor and developer of such well known hits as Haskell and QuickCheck. His paper, also written in the 80’s, emphasizes that modularity is the major source of power that puts functional programming ahead of its procedural counterparts, most notably Object Oriented Programming languages. The modularity is exmplarized through use of two new “Functional Glues” that Hughes defines as Higher-order functions and Lazy-evaluation.

Excellent Programming Languages

One of the slides I presented, gave a terse sampling of the functional programming languages I consider worth your while as a modern day developer. I listed four languages, requiring to limit my selection for brevity:

  1. Haskell
  2. Clojure
  3. Elixir
  4. F#

All four of these languages share certain qualities and features and this correlation is not a coincidence. Afterall, John Hughes tells us at least two of the features we want are Higher-order Functions and Lazy-Evaluation, which unsurprisingly each of these languages support wholeheartedly. It’s also true that there are other excellent functional language features supported by all four of these choices. For example, pattern matching, partial evaluation, immutability, and referential transparency all stand out in my mind. There are also notable differences between these four languages. Haskell and F# will be the languages you choose if you want to get your hands dirty with category theory constructs such as functors and monoids. Conversely, Clojure and Elixir’s type systems are dynamic. Elixir is an excellent choice for concurrency due to Erlang’s amazing OTP which it integrates with seamlessly. Clojure’s emphasis on “code-as-data” I find well suited for the functional paradigm.

After letting this slide sink in, I noticed a correlation that you may find interesting. The order of languages on the slide represents the priority I would recommend as being best to learn. The surprising bit is the reverse order would be my recommended priority when deciding what languages to use in production.

Am I contradicting myself? Would I waste your time by telling you to learn one language but then turnaround and devalue it as non-practical? Actually, everything is alright and this will all make perfect sense (bear with me!) I believe both points of view are valuable and complementary; not contradictory. Allow me to explain…

The Explanation

What it boils down to is the following argument.

The value of learning a language is not simply being able to use that language in production code.

Namely, the student learning a particular language can enjoy the following benefits:

1. understanding the core principles of the paradigm
2. knowing where the core ideas come from

In this list, Haskell is the de facto grandfather of the other languages. Therefore, if you want to learn the origins of functional programming, that is the place to start. Likewise, learning Haskell is learning the fundamentals of the paradigm because the gap between language and principles is reduced. Finally, Haskell is a pure functional language, implying there aren’t any non-functional features. Therefore, you won’t lose focus by being distracted away from the functional oriented constructs.

The languages going down the list add incremental amounts of non-pure abstractions. We generally refer to these as “pragmatic” features. F# is at the opposite end of the spectrum. It supports the full weight of OOP and FP, and runs on the .NET CLR. It bears noting that, in my books, Elixir and Clojure are nearly tied in this respect. I really could have listed them the other way around and made the same arguments here.

A Different Point Of View

Next up, let’s look at the languages in the reverse order. I am now recommending the languages in decreasing order of. Here are the criteria I’m using to evaluate the relative ordering:

1. Community adoption
2. Recent growth

To be fair, F#, Clojure, and Elixir all are actively being expanded within their resepective communities. Haskell is a bit older and was established a long time ago but there just aren’t that many jobs available locally in the Haskell space. However, when it comes to community adoption, at least in the prairies, F# is the most common choice for functional language. Many local businesses are seeing more and more adoption of F#. This is evidenced by the fact that our user groups and developer conferences have had more F# talks in the last year than any functional language talks combined.

Conclusion

I love functional languages and the four I’ve listed are all excellent. Haskell, Clojure, Elixir, and F# are all excellent languages that are ready for you to learn and use in production (albeit with different considerations for each). If you want to go far, learn Haskell first. If you want to go fast, learn F# first. My favorite language is Clojure! Really, you can’t go wrong if you choose one and stick with it.