[rust-dev] Fwd: &self/&mut self in traits considered harmful(?)

Patrick Walton pcwalton at mozilla.com
Thu Jun 19 10:04:55 PDT 2014


On 6/19/14 4:59 AM, SiegeLord wrote:
> Regardless, bignum and linear-algebra are prime candidates for operator
> overloading, but the way it is done now by most implementations is just
> unsatisfactory. Maybe bignums in std::num and all the linear algebra
> libraries could be converted to use a lazy evaluation, thus avoiding
> this issue of changing the operator overload traits. Alternatively,
> maybe the whole operator-overloading idea-via traits is broken anyway
> since operators do have such different semantics for different types (in
> particular, efficient semantics of operators differ from built-in
> numeric types and complicated library numeric types). Maybe adding
> attributes to methods (e.g. #[operator_add] fn my_add(self, whatever) {}
> ) is more flexible since it is becoming clear that generic numeric code
> (generic to bignums and normal integers and matrices) might not be a
> possibility.

That's introducing ad-hoc overloading and does not interact well with 
non-ad-hoc generics. I always felt that Haskell's approach was better 
for code readability: allowing user-defined symbolic operators. That way 
if `+`'s signature is not to your liking, you can define `+.` or 
whatever and get most of the benefits of overloading, while maintaining 
the invariant that the readers of the code always know what the 
signature of `+` is.

Patrick


More information about the Rust-dev mailing list