Don’t forget Erlang
Everyone should learn to think functionally and recursively. But how? With which language? I think that one of the best options for functional programming is largely overlooked …
At some point in your computer science education you were probably exposed to Lisp. Perhaps you worked through part of the SICP book, or maybe The Little Schemer. If not, I highly recommend the latter.
But most of us get tired of Lisp. Even though it has been used very effectively in cases, it feels like a trick, an academic ploy to unsettle our previous convictions about programming languages.
If you are still interested in functional languages, you are likely to try Haskell next. (Probably starting with Learn You A Haskell.) Haskell has enough syntax to feel like a real language, and if (like me) you have a background in mathematics, it is loads of fun. I spent some time working Project Euler problems in Haskell (here), and it felt like cheating. Once a problem is solved mathematically, it isn’t much trouble to translate it to Haskell.
Haskell isn’t just for mathematics, of course. It is a great place to learn to think functionally, and to gain comfort with recursion and functional concepts like map, filter, and fold.
But Haskell wore me out in the end. The quest for functional purity has lead Haskell to an impractical place, which was never more clear to me than the day that I spent several hours studying monads so that I could read from a text file. It was that day that I was convinced that Haskell would never be relevant in industry.
Recently I started learning Erlang on a whim, using Learn You Some Erlang. It’s my favorite so far. It’s not painful to read, like Lisp. And I don’t have to worry about types and monads, like in Haskell. You are required to think functionally, as you cannot change the state of a variable … but Erlang doesn’t worry about purity, which is refreshing.
Erlang is clearly not my first functional language, but I think that it would be an excellent choice as such. It lacks the most intimidating aspects of Lisp and Haskell, but without allowing for procedural code. And as a bonus, Erlang has some sort of super-awesome concurrency model that is extremely parallelizable. I don’t know anything about this yet, but I’m looking forward to learning about it.