# Is there a way overload a function, \`fn\`, in a \`Module Module1\` so that it can only be called using \`Module1.fn\`?

**URL:** <https://discourse.julialang.org/t/is-there-a-way-overload-a-function-fn-in-a-module-module1-so-that-it-can-only-be-called-using-module1-fn/30104>\
**Category:** New to Julia\
**Created:** [October 20, 2019, 11:24am UTC](https://discourse.julialang.org/t/is-there-a-way-overload-a-function-fn-in-a-module-module1-so-that-it-can-only-be-called-using-module1-fn/30104 "2019-10-20T11:24:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [October 20, 2019, 11:24am UTC](https://discourse.julialang.org/t/is-there-a-way-overload-a-function-fn-in-a-module-module1-so-that-it-can-only-be-called-using-module1-fn/30104/1 "2019-10-20T11:24:46Z")

</div>

I am defining `size` in my module `JDF`, but I only want it to ever be called using `JDF.size`. Can I do that?

```julia
module JDF

using Base:size

JDF.size(df, val) = JDF.size(df, Val(val))

JDF.size(df, ::Val{1}) = 1
JDF.size(df, ::Val{2}) = 2
end

```

Now

```julia
@which size("abc", 1)

```

shows the location in my JDF, even though I didn’t `export` it.

Is there a way to do it so that `JDF.size` needs to be called and `size` ignores the function defined in the module JDF?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 20, 2019, 11:48am UTC](https://discourse.julialang.org/t/is-there-a-way-overload-a-function-fn-in-a-module-module1-so-that-it-can-only-be-called-using-module1-fn/30104/2 "2019-10-20T11:48:48Z")

</div>

Your code as written is invalid for multiple reasons:

1. first, you want `using Base: size`

2. second, you can’t redefine `size` without importing it, so that part will error too.

So I am curious how you got this even to run.

Do you need something like

```julia
baremodule JDF
using Base: Base, Val
size(df, val) = size(df, Val(val))
size(df, ::Val{1}) = 1
size(df, ::Val{2}) = 2
end

```

?

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [October 20, 2019, 11:50am UTC](https://discourse.julialang.org/t/is-there-a-way-overload-a-function-fn-in-a-module-module1-so-that-it-can-only-be-called-using-module1-fn/30104/3 "2019-10-20T11:50:18Z")

</div>

My actual code was a lot longer, so I try to get the essence by writing a MWE. Fixed.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 20, 2019, 11:53am UTC](https://discourse.julialang.org/t/is-there-a-way-overload-a-function-fn-in-a-module-module1-so-that-it-can-only-be-called-using-module1-fn/30104/4 "2019-10-20T11:53:35Z")

</div>

You didn’t fix it — please read item 2; code above still errors.

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [October 20, 2019, 11:55am UTC](https://discourse.julialang.org/t/is-there-a-way-overload-a-function-fn-in-a-module-module1-so-that-it-can-only-be-called-using-module1-fn/30104/5 "2019-10-20T11:55:44Z")

</div>

Truly fixed now. I just ran it. I think I encountered the error and had done what I have been doing there. At some point I had `import Base: size`. Maybe that’s why it didn’t work.
