You could do something like this:
defmodule MyDecimal do
defmacro __using__(_) do
quote do
import Kernel, except: [+: 2, -: 2, ...]
def left + right do
Decimal.add(left, right)
end
def left - right do
Decimal.sub(left, right)
end
# ...
end
end
end
For me, the lack of operator overloading is part of what makes Elixir a good dynamic language as it still cares about types. It’s also part of (all of?) what is enabling the possibility of strong arrows (if we get some static typing). If you looked at a language like OCaml it goes even further. + only adds ints, you need to use +. to add floats! And you must explicitly cast one side if you want to add a float to and int.
I don’t know if this is the exact reason Elixir doesn’t overload, though.






















