News for hackers. Stuff that matters.
Re:The Swift compiler is slow due to how types are inferred by adamwk on Wednesday June 12, 2024 @05:49PM (#40663594)
the rust traits are not overloading though (at least not in the same way as swift), that’s just implementing a trait on a type. I think the distinction is that with traits or protocols you get a lot of expressivity, reducing the need for overloading
Re:The Swift compiler is slow due to how types are inferred by lamontcg on Thursday June 13, 2024 @12:38AM (#40666001)
You can still create your own vec3 though that implements "<vec3> * <double>" through the Trait... It seems at least superficially equivalent to operator overloading.
Re:The Swift compiler is slow due to how types are inferred by fauigerzigerk on Thursday June 13, 2024 @03:06AM (#40666820)
It is operator overloading. Traits are just the mechanism to do operator overloading in Rust.

But I think what matters in this particular context is that Rust does not support function overloading and this restriction also applies to functions implementing operators. I think this may be why the parent comment claims that it is not really overloading. The meaning of "overloading" is a bit ambiguous here.

So for a concrete type vec3 you cannot define both <vec3> * <double> and <vec3> * <vec3>, which makes type inference a lot easier. It also makes Rust operator overloading less expressive.

Re:The Swift compiler is slow due to how types are inferred by yorwba on Thursday June 13, 2024 @06:41AM (#40667985)
You can define multiple implementations for the Mul trait with different right-hand sides, no problem at all.

https://play.rust-lang.org/?version=stable&mode=debug&editio...

Re:The Swift compiler is slow due to how types are inferred by fauigerzigerk on Thursday June 13, 2024 @07:50AM (#40668474)
Thanks, I didn't know that.

In light of this, would you say that there is any sense in which Rust doesn't support the full extent of what is usually called operater overloading?

Re:The Swift compiler is slow due to how types are inferred by lamontcg on Thursday June 13, 2024 @06:35PM (#40675621)
I'm not who responded to you, but I think the important difference from some other languages is you can't define arbitrary operators, but there does seem to be Traits for overloading at least most of the built-in operators.