Function name conflict: ADL / function merging?

C is different because it doesn’t have any single-dispatch or operator overloading.

C++ is as I described it. I think Java is similar to C++. Without doing a survey, I can tell you that every single-dispatch language behaves as I have said. It is just a little easier in a dynamic single-dispatch language to know where to look for functions because if I call myval.f() it only need to look in the namespace/type associated with the myval and not in other places. That is why C++ and other languages need more complicated ADL rules so that f(myval) and f(myval1, myval2) can still work.

For python, of course you have to go import numpy, and you need to qualify with numpy.array to create the object, but after that the language knows where to lookup the functions given the single-dispatch and operator overloading. I won’t say many nice things about python, but that works and you certainly don’t need to mess with a global namespace

There is nothing at all magic about most of these languages! When it encounters a + function it looks at the namespaces of the types of the arguments to look for a + function which matches the arguments. Same when it sees a f(myval) or myval.f(). Nothing built-in or special, just argument-dependent lookups.

2 Likes