Proposal: empty-var args should dispatch to most general method #42222
Labels
breaking
This change will break code
speculative
Whether the change will be implemented is speculative
types and dispatch
Types, subtyping and method dispatch
This is a proposal for consideration for whenever we get around to Julia 2.0.
Writing it here so it is not lost to time.
This would resolve #24315 (though that issue is labelled [docs] so I am making a new one for a non-docs based solution.)
In julia the normal rule of dispatch is to the most specific method.
This even applies when that method becomes the most specific due to having varargs, and when those varargs are not passed:
Now there are a few options for how to resolve this (when we are considering that breaking is an option).
Vararg
so it only matches 1+ arguments.I would like to make the argument that empty varargs should always go to the most general way of meeting that constraint.
Inverting the normal rules.
The reason for this is not so complex:
The whole motivation of adding a dispatch with a specific type, is that you can use insights based on knowing your object has that type to write a better method.
For some definition of better: whether faster, more correct, etc.
But if you are given no actual instance of your type, then there is no way you have an additional insight -- if you did that insight would be applicable in every case no matter the argument type, so i would expect it to be in the more general method that already existed before you brought up your type.
And this change would allow that method to be hit.
The downside is this is another rule to remember, and implement.
The upside is it would remove a lot of cases of accidental type-piracy.
And doesn't introduce more ambiguity errors, nor require writing extra methods.
The text was updated successfully, but these errors were encountered: