Tim Bray and Cédric Beust each make good points about Erlang's error reporting. My first reaction was: apparently they've not used Haskell. But coming back around, I do agree that the messages can be confusing, especially to beginners, especially to beginners whose mindset is in the typical assignment-oriented, imperative C/C++/Java model of computing.
Pattern matching errors can result in a "bad match" message. When you thought you were doing assignment, and you forgot you forgot you cannot "re-assign" different values to the one some variable already has, then having the system tell you "bad match" is going to cause some grief.
Learning anything new, and especially "re-learning" something you thought you already knew, will take time. Grant it, that effort may not always pay off. Maybe it's just not your cup of tea. On the other hand what I learned about programming in Erlang is that a few error messages pop-up with some regularity, and I now am fairly quick to identify the cause.
Good practices to aid diagnosing errors are:
- Write a little code at a time.
- Test-drive that code using an xUnit framework or just using the erl command line.
- Use pattern matching and guards to narrow the acceptable parameters to a function.
That top-level function looks as though it should expect a list, and not an atom. So this would have helped greatly...
Or maybe better...
scan(Arg) when is_list(Arg) -> ...
Cédric also says Erlang "feels old"... so do I sometimes, but I still have something left every now and then. :-D
scan() -> %% Empty list, do the default thing... ; scan([Head | Tail]) -> %% Do something with Head then recursion on the Tail... ... scan(Tail).