[Pitch 2] Light-weight same-type requirement syntax

Spelling it == doesn’t avoid having to choose between func ==(lhs: A, rhs: B) and func ==(lhs: B, rhs: A). Swift still privileges the type of the left-hand side, so you have to write definitions of both functions. Some people consider this redundancy a damning indictment of languages without multimethods.

The argument that one “really” wants “multi-Self protocols” feels like the same argument. It’s also a straw man, because Rust doesn’t implement conversions using a trait with 2 generic parameters. It models conversions using two separate traits, From<T> and Into<T>. A single generic impl<T, U> Into<U> for T provides the Into that mirrors any user-defined impl From.

That, @Slava_Pestov, is the usefulness of generic traits—though perhaps you could call it generic impls, because the arity of the impl does not match that of the trait! But even though impl Into has two type parameters, it’s very clear which is Self, because the impl is for one of them.

Edit: Maybe conditional conformances provide the equivalent functionality to this use of generic impls?

1 Like