In Erlang and Elixir, and unlike many other languages (such as C#), functions are uniquely identified by their name and arity, so technically foo(bar)
and foo(bar, baz)
are totally different functions. But that's really just a technicality, to write an 'overloaded' function in Elixir, you would write something like the following definition of sum
:
defmodule Math do
def sum(list), do: sum(list, 0)
def sum([], acc), do: acc
def sum([h|t], acc), do: sum(t, acc + h)
end