Search in record list
Mon Mar 20 07:13:33 CET 2006
Den 2006-03-20 06:22:04 skrev Bengt Kleberg <>:
> On 2006-03-18 16:41, Kostis Sagonas wrote:
>> IMO, the compiler, to the extent it can, should warn about redundant
>> clauses. Currently, there is a check for redundant clauses, but it
>> is very rudimentary. It can be improved. For example, the compiler
>> could warn for the above and also for `similar' functions as e.g.
>> b(N) when is_number(N) -> number;
>> b(I) when is_integer(I) -> integer.
> is it documented that function cluses are tried in
> the order they are written?
> otherwise i think that it would be nice if the
> compiler could ''rearrange'' these 2 cluses for me,
> so that
> b(1) => integer
Conceptually, matching is always carried out in the
order in which the clauses are written. This is
specified in the Erlang Reference Manual, ch 5.2.
A reasonable interpretation is that the compiler is free to
rearrange the clauses only as long as it doesn't
change the semantics of the program.
In this case, the compiler could (and will) warn you that
you have a clause that will never match, but since
rearranging the clauses would change the return value,
you can rest assured that it will _not_ be done. (:
More information about the erlang-questions