[erlang-questions] Function Declaration Syntax
Jesper Louis Andersen
jesper.louis.andersen@REDACTED
Fri May 13 23:44:10 CEST 2011
On Fri, May 13, 2011 at 22:23, Joe Armstrong <erlang@REDACTED> wrote:
> No good reason. Erlang evolved from Prolog and that how it was done in
> Prolog
> no deep thought was involved ..
Interestingly, that is also the style of Haskell:
len :: [a] -> Integer
len [] = 0
len (x : xs) = 1 + (len xs)
And also of Standard ML:
fun len [] = 0
| len (x :: xs) = 1 + (len xs)
..
My usual rewrite in many cases is to use a case. It almost notates as
the original idea of a simplification of the syntax:
len(L) ->
case L of
[] -> 0;
[_|R] -> 1 + len(R)
end.
--
J.
More information about the erlang-questions
mailing list