[erlang-questions] head mismatch

Richard A. O'Keefe ok@REDACTED
Wed Feb 11 02:52:02 CET 2015

I suppose I should point out

sum(N) when is_integer(N), N >= 0 ->
    sum(0, N).

sum(L, U) when is_integer(L), is_integer(U), U >= L->

I should also point out that I don't find "sum_acc"
an intention-revealing name.
>>> Am I not alllowed to do this 
>>> sum(x) -> 
>>>    x ; 
>>> sum(x,y) ->
>>>   x + y.   
>>> or is there something else missing ?

Can I suggest a strategy for dealing with such questions?

Try it.

sum(X) -> X; % is this OK?
sum(X, Y) -> X+Y.

Compile it.  The compiler _will_ complain.  It will be the
same "head mismatch" error you saw.

The compiler could be more helpful.  Instead of saying
"head mismatch", it could say
"Error: function sum/1 is followed by a clause for sum/2 but
there is no full stop at the end of sum/1."

More information about the erlang-questions mailing list