Yeah, I misunderstood what you said.
That’s true, but you are one step away from overcoming this problem, because it is always possible to change one public function into one public function and the private function clone, like this:
defmodule Foo do
def foo(a, b) when is_integer(a) and is_integer(b), do: a + bar_in_foo(b)
def bar(b) when is_integer(b), do: b + 1
defp bar_in_foo(b) when is_integer(b), do: b + 1
end
Every compiler can do this automatically and this optimization is called “speculative specialization” and while it increases the module size, it is fairly cheap in all the BEAM languages and can be applied almost everywhere


















