# Function name conflict: ADL / function merging?

**URL:** <https://discourse.julialang.org/t/function-name-conflict-adl-function-merging/10335>\
**Category:** Internals & Design\
**Tags:** proposal, namespaces\
**Created:** [April 14, 2018, 5:16pm UTC](https://discourse.julialang.org/t/function-name-conflict-adl-function-merging/10335 "2018-04-14T17:16:17Z")\
**Posts on this page:** 1\
**Showing post:** 209

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [April 21, 2018, 2:03pm UTC](https://discourse.julialang.org/t/function-name-conflict-adl-function-merging/10335/209 "2018-04-21T14:03:18Z")

</div>

Let me preface this by saying that if all that comes out of this whole discussion is a thorough understanding of why ADL does work for C++ (for some definition of ‘work’) while it doesn’t make sense for Julia, I think this whole discussion, or at least parts of it 🙂, will have been very worthwhile. But I think there is hope for an ADL-like approach in Julia in the sense Jeff described:

> [@jeff.bezanson](#):
>
> Now, it’s possible that f could be an object that implements a form of ADL over its arguments. But it’s these objects that would populate the “single global namespace” of function names — there has to be some namespace that maps the name f to an object that does what you want, and you have to be able to see that binding.

I was definitely wrong in [this comment](https://discourse.julialang.org/t/function-name-conflict/10335/197), for any sensible interpretation of an `Any` type analogue in C++.

First, the interpretation of `f(x::Any)` as a function template. The following program compiles:

```cpp
namespace XNamespace {
    struct X { };
    
    template <typename T>
    auto f(T) {return 1;}
}

int main() {
    XNamespace::X x;
    f(x);
    return 0;
}

```

Second, if `Any` is treated as the universal base class, we get

```cpp
namespace Base {
    struct Any { };
}

namespace XNamespace {
    struct X : public Base::Any { };
    
    auto f(const Base::Any*) {return 1;}
}

int main()
{
    Base::Any a;
    f(&a); // error: 'f' was not declared in this scope (because Any is not defined in XNamespace)
    
    XNamespace::X x;
    f(&x); // fine
    return 0;
}

```

In a way this is a good thing, since I agree that the issue Jeff raised [here](https://discourse.julialang.org/t/function-name-conflict/10335/204) about a function becoming applicable as a result of signature narrowing would otherwise be a showstopper.

By the way, [this account](http://www.drdobbs.com/cpp/a-personal-note-about-argument-dependent/232901443) by Koenig lookup’s (ADL’s) namesake makes it sound like ADL was originally added for reasons of backwards compatibility (figures…) at the time of the introduction of namespaces in C++. Just a historical note; this is not meant as an argument against ADL.

---

_[View the full topic](https://discourse.julialang.org/t/function-name-conflict-adl-function-merging/10335)._
