The only complexity is figuring out OTP, which in itself is very easy to use, but you must understand all the underlying abstraction it's masking before really being good at it.
Once you get familiar with the boilerplate of distributed systems and see how OTP helps eliminate much of it, with a best-practice design figured out for you, that's when you really start to respect Erlang.
Of all the languages I've learned on the side I think Erlang/OTP has the most amount of features I feel are missing from other languages (proper pattern matching being the biggest).
F# patterns come from ML, with active patterns added on top. Erlang patterns come from Prolog, with unification removed.
A quick example, in Erlang you can write:
1> (X = {1 = A, [2, 3]}) = {1, [2, 3]}.
{1,[2,3]}
As well as: 1> ({A = 1, [2, 3]} = X) = {1, [2, 3]}.
{1,[2,3]}
That is, the `=` is actually a pattern matching operator and the order of its two operands doesn't matter (well, not really, not everywhere - that's where the "removed unification" comes from - but close enough). That's because in Prolog the `=` operator denotes actual equivalence, not an assignment, and Erlang inherited that.In F# and OCaml this is done with a special operator, `as`, and it cares about the order of its operands very much. You can do this:
> let (1 as a, [2; 3]) as x = (1, [2; 3]);;
val x : int * int list = (1, [2; 3])
val a : int = 1
but > let (a as 1, ...etc
obviously won't work.All in all, both mechanisms work quite well and you can translate between them easily, but they are not 100% equivalent. Erlang has much simpler syntax (it's basically just `=`) while F# adds `as`, `&` and other constructs. In Erlang, once a name is matched with an expression, it is equivalent to that expression and stays that way forever. In OCaml, you can readily reassign matched names. That also makes Erlang pattern matching act like an assert and (identity) comparison in some situations, which are both different things in F#.
So, the use-cases are very similar, but the concepts underlying the mechanisms differ which in turn makes some details of the mechanisms differ too. Both are a joy to work with, to be sure, compared to the "applied ifology" or the dreaded `switch` statement, though :)
It basically uses pattern matching as a fundamental/primitive part of the language design, rather than some useful add-on or tertiary feature.
case X of
{expense, N} -> Total - N;
{invoice, N} -> Total - N;
{loss, N} -> Total - N;
{credit, N} -> Total + N
end
whereas in ocaml (and F#, modulo details) you could just do something like: match x with
| (`expense, n) | (`invoice, n) | (`loss, n) -> total - n
| (`credit, n) -> total + n;;
The examples are unidiomatic and artificial and you can sometimes ameliorate it with guards, but it's a frequent (minor) annoyance. case X of
{Cat, N} when Cat == expense; Cat == invoice; Cat == loss -> Total - N;
{credit, N} -> Total + N
end> you can sometimes ameliorate it with guards
which is exactly what you did, so I don't think you're disagreeing here :)
In Erlang's case (pun intended!) I'd probably go for a function though:
total({expense, N}, Total) -> Total - N;
total({invoice, N}, Total) -> Total - N;
total({loss, N}, Total) -> Total - N;
total({credit, N}, Total) -> Total + N.