Erlang summary

I just finished reading Joe Armstrong’s “Programming Erlang: Software for a Concurrent World.” The first part was a bit slow for a someone familiar with other functional languages. I thought a brief summary of the language might be useful.

What you need to know:

  • Erlang is a strict functional language similar in syntax to the ML family of functional programming languages (like Caml, Miranda and Haskell), but not a descendant (lists have commas for example).
  • Erlang has immutable state only (there are some mutable state options, you’re not supposed to go there).
  • Erlang uses pattern matching to define functions, unpack data structures, etc. A set of function clauses have the same arity. A function with the same name and different arity is a different function. The pattern matching is heavily used and is pretty cool.
  • Erlang has case statements, exceptions, anonymous functions (“funs”), list comprehensions and pattern guards.
  • Atoms are just handy values. Like blah. Yes, blah is a valid atom. Erlang doesn’t really have strings. On a full moon, when the weather is just right, lists of numbers become strings for a short time, but immediately change back. I’ve heard that if you fire 2 Erlang number lists around the LHC, they concatenate.
  • Erlang doesn’t have abstract types, just literals, lists, tuples and records (tuples with named members). There is an interesting convention of representing data structures as a tuple tagged with an atom prefix, e.g. {point, 5, 15}. This works nicely with pattern matching.
  • Erlang is really sweet for writing concurrent programs. It uses messaging passing to communicate between processes. No shared memory, no locks, programs can break out into multiprocessing way more easily than in other languages, particularly imperative ones. Work can be moved to other processes easily, other processes can be on other nodes easily. What Perl is to text processing, Erlang is to concurrency.
  • Open Telecoms Platform (OTP) is an environment for running server applications, a bit like a J2EE container. It provides a bunch of useful generic code for things like supervising processes so you don’t have to. Dynamic code loading is part of the Erlang VM. There’s a lot of useful systems code and tools in the Erlang distribution.
  • Amazon’s SimpleDB is written in Erlang (real world example!).

Armstrong’s book is a great intro. I picked it up because I had a few conversations about Erlang over the last few months. It’s an interesting language. I can’t quite remember what, but something made me feel that Erlang was going to be an interesting skill to have in the coming years, that we would be hearing more of it. It may just be a passing fad, but it has delivered some heavyweight systems.

Armstrong designed and implemented the first version of Erlang in 1986.