[erlang-questions] Function Declaration Syntax
Sat May 14 13:34:11 CEST 2011
On Fri, May 13, 2011 at 23:44, Jesper Louis Andersen <
> On Fri, May 13, 2011 at 22:23, Joe Armstrong <> 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)
This is - in my book - a step backwards.
You should haev the spec for the function and then pattern matching in the
function clauses since it gives you:
1. Overview of what the function does.
2. 1st level overview of how the function branches out.
This makes debugging so much faster than having to get inside a function
only to meet a case on the parameters as the first thing.
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions