I wonder if referencing “function overloading” in context of Elixir/Erlang should best be avoided. In other languages overloaded functions are separate functions discriminated by arity and/or parameter types. In Elixir functions of the same name but different arity are separate functions - but other than that:
- the terminology of “multi-clause function”
- the fact that the order of the clauses matters
- and the fact that the syntax for a multi-clause anonymous function looks like this:
iex> my_function = fn
{:ok, x} -> "Everything is ok: #{x}"
{:error, x} -> "There was an error: #{x}"
end
all suggest that all the clauses of the same arity (and name) belong to the same function. Sure patterns and guards can mimic discrimination by parameter type - but in principle each clause is part of the same function.
So when the documentation states things like:
Specifications can be overloaded just like ordinary functions.
@spec function(integer) :: atom
@spec function(atom) :: integer
it's bound to create confusion.