# Export functions included from different modules with the same name

**URL:** <https://discourse.julialang.org/t/export-functions-included-from-different-modules-with-the-same-name/47307>\
**Category:** New to Julia\
**Created:** [September 26, 2020, 11:26am UTC](https://discourse.julialang.org/t/export-functions-included-from-different-modules-with-the-same-name/47307 "2020-09-26T11:26:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![iHany](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihany/32/18151_2.png) [@iHany](https://discourse.julialang.org/u/iHany)\
**Post date:** [September 26, 2020, 11:26am UTC](https://discourse.julialang.org/t/export-functions-included-from-different-modules-with-the-same-name/47307/1 "2020-09-26T11:26:52Z")

</div>

Here is my example:

```julia
module AB

using Reexport

include("A.jl")
include("B.jl")

@reexport using .A
@reexport using .B

end

```

And, both A, B has functions `close!`. Then, using `close!` causes warning like this:  
`WARNING: both A and B export "close!"; uses of it in module AB must be qualified`  
(Of course, both A.close! and B.close! accept different types of arguments).

Is there something I missed?

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [September 26, 2020, 11:38am UTC](https://discourse.julialang.org/t/export-functions-included-from-different-modules-with-the-same-name/47307/2 "2020-09-26T11:38:43Z")

</div>

Yes, this is impossible. It has been requested elsewhere (under the limitation you mention that the two functions take strictly different arguments) but I don’t know if it’s on anyone’s roadmap to do this (maybe by 2.0).

What you should do is have AB define `close!`, and then A and B add methods to it

```julia
# in AB

# no methods, just defining the name
function close! end

export close!

```

```julia
# in A
import AB: close!

close!(x) = #...

```

---

<div class="post-metadata">

**Author:** ![iHany](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihany/32/18151_2.png) [@iHany](https://discourse.julialang.org/u/iHany)\
**Post date:** [September 26, 2020, 1:34pm UTC](https://discourse.julialang.org/t/export-functions-included-from-different-modules-with-the-same-name/47307/3 "2020-09-26T13:34:07Z")

</div>

@tomerarnon  
Thank you very much!  
I’m a little bit new to Julia, so I’m little bit confused.  
Is it a kind of extension of existing functions?

---

<div class="post-metadata">

**Author:** ![lhnguyen-vn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lhnguyen-vn/32/15449_2.png) [@lhnguyen-vn](https://discourse.julialang.org/u/lhnguyen-vn)\
**Post date:** [September 26, 2020, 1:42pm UTC](https://discourse.julialang.org/t/export-functions-included-from-different-modules-with-the-same-name/47307/4 "2020-09-26T13:42:27Z")

</div>

They will be methods under the `close!` function. The multiple dispatch design of Julia means that you can have methods acting on different tuples of argument types under the same function name. In this case the recommended way is to declare the function in `module AB`, and add methods to it from `module A` and `module B`.

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [September 26, 2020, 2:44pm UTC](https://discourse.julialang.org/t/export-functions-included-from-different-modules-with-the-same-name/47307/5 "2020-09-26T14:44:03Z")

</div>

> [@iHany](#):
>
> Is it a kind of extension of existing functions?

Yes, exactly. It is the same idea as when you implement an object that should have `length(obj)`, you do

```julia
Base.length(x::MyType) = # ...

```

to extend the function `length` from Base to your own type. In your case, the `AB` package creates an interface that `A` and `B` extend for their own specific cases, which is a common design pattern.
