Some multiple dispatch magic


#1

Now that me have got multiple dispatch landed. Do we need some magic like 2*"foo" == "foofoo", 1+"bar" == "1bar" , 2u + 1i == 3u? it just needs adding some impls to the standard library.

E.X. impl<'a> Add<&'a str,&'a str> for int { fn add(&self, rhs: &'a str) -> &'a str { /* some code*/ } }


#2

I must admit that having used the 2 * "foo" in python, it’s something I could definitely get behind; it can really be handy, for example when computing padding.

However the 1 + "bar" feels weird. In C, the result is "ar"; that is it’s just pointer arithmetic, and 5+"bar" is undefined behavior.

Similarly, the 2u + 1i might seem logical, but what about 2u + (-3i) ? In this case, it would feel more natural for the result to be signed, because in regular uses you are far more likely to end up with negative quantities than with quantities so big they do not fit in 32 or 64 bits.