Is there a simple way to overload functions?

I thought about this in the past, and I recall there being a tricky case with functions that are used as path expressions.

// where `fn foo<T>` exists
let f = foo; // or equivalently, foo::<_>

Currently, the type of a f would be a ZST representing fn foo with a single unknown generic type argument. Notice that the type parameters are part of the type rather than part of the Fn{Mut,Once} impls; that's what makes turbofish syntax possible.

Notice how the arity is not known yet because we didn't call it. So I think even overloading on arity will lead to complications, but I am not sure.


I definitely think this is possible. As long as only a single function signature appears in the source code, I don't think there is any ambiguity.

The bigger issue here would be convincing other Rustaceans that the feature is worthy of inclusion! I am divided on the issue; I think I've seen some cases where it would be nice, but the feature doesn't offer much power (e.g. if you have two default arguments, you can't skip one unless the language also has keyword arguments), and using the Builder pattern offers more possibilities for future API evolution.