Comment

Comment by losvedir

> because overloading introduces ambiguity that cannot be resolved at the code-unit level

Can you explain this a bit? Operator overloading just seems like such a strange bugbear of Zig folks to me. Maybe I've just never been bitten by it, but at least in Elixir, my main language, I've never really understood the danger.

Are operators truly so different from functions? You'd expect that any function you import could do, well, anything. Aren't operators essentially just the same thing, just with a "prelude" in the language that basically imports them by default?

In Elixir, you might have (discouraged):

    defmodule MyMod do
      import MyOperators
and then you know to check what's defined by MyOperators, for that module. But more common, if you really wanted to overload, would be to be more specific:

    defmodule MyMod do
      import MyOps, only: [+: 2]
and then you know plus (with two arguments) has a different meaning in that module.
parent losvedir 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton