Remix.run Logo
▲ ogogmad 2 days ago

Is there a way to support varying the meaning of "+" etc without introducing a lot of complexity? I suppose if Zig had nested functions, and the ability to define a nested function called "+", then you could have name shadowing instead of "overloading".

OCaml basically gives you operator overloading this way without actually doing overloading. I'm wondering why we can't have these OCaml-isms in other languages - without needing to use OCaml - which sadly comes with other commitments.

▲dnautics 2 days ago | parent [-]

I always thought custom infix operators would be easy and basically what people want, e.g:

    const @<+> = @import("op.zig").special_add;

    const c = (a <+> b);
    //syntactic sugar for @<+>(a, b)