# How to define function input type a struct from a different module?

**URL:** <https://discourse.julialang.org/t/how-to-define-function-input-type-a-struct-from-a-different-module/41031>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [June 9, 2020, 1:57am UTC](https://discourse.julialang.org/t/how-to-define-function-input-type-a-struct-from-a-different-module/41031 "2020-06-09T01:57:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saad\_Mahmud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/saad_mahmud/32/15518_2.png) [@Saad\_Mahmud](https://discourse.julialang.org/u/Saad_Mahmud)\
**Post date:** [June 9, 2020, 1:57am UTC](https://discourse.julialang.org/t/how-to-define-function-input-type-a-struct-from-a-different-module/41031/1 "2020-06-09T01:57:12Z")

</div>

I have just started to learn Julia. I am having difficulty defining function input type. Consider this 3 files:

```julia
#Mymodule.jl
module Mymodule
    export getP, point
    
    mutable struct point
        x::Int32
        y::Int32
    end

    function getP()::point
        return point(1,2)
    end
ende here

```

```julia
#Mymodule2.jl
module Mymodule2
    include("Mymodule.jl")
    using .Mymodule
    
    export mut1,mut2
    
    function mut1(a)
        a.x = -1
    end
    function mut2(a::point)
        a.x = -3
    end
end

```

```julia
#test.jl
include("Mymodule.jl")
using .Mymodule
include("Mymodule2.jl")
using .Mymodule2
a = getP()
println(a.x)
function mut3(a::point)
    a.x= -2
end
mut3(a)
mut1(a)
mut2(a)

```

Even though mut3() and mut1() works; mut2() does not. and gives the following error message:

```julia
ERROR: LoadError: MethodError: no method matching mut2(::point)
Closest candidates are:
  mut2(!Matched::Main.Mymodule2.Mymodule.point) at /home/saadmahmud/Documents/Halite/testjulia/Mymodule2.jl:11
Stacktrace:
 [1] top-level scope at none:0
 [2] include at ./boot.jl:317 [inlined]
 [3] include_relative(::Module, ::String) at ./loading.jl:1044
 [4] include(::Module, ::String) at ./sysimg.jl:29
 [5] exec_options(::Base.JLOptions) at ./client.jl:266
 [6] _start() at ./client.jl:425
in expression starting at /home/saadmahmud/Documents/Halite/testjulia/TestMain.jl:12

```

The only difference between mut1() and mut2() is that I defined the input type. What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![ettersi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ettersi/32/6829_2.png) [@ettersi](https://discourse.julialang.org/u/ettersi)\
**Post date:** [June 9, 2020, 3:40am UTC](https://discourse.julialang.org/t/how-to-define-function-input-type-a-struct-from-a-different-module/41031/2 "2020-06-09T03:40:37Z")

</div>

What you are doing wrong is that you are including `Mymodule.jl` twice (once inside `Mymodule2`, once in `test.jl`). This effectively creates two copies of `Mymodule`, namely `Base.Mymodule` and `Base.Mymodule2.Mymodule`. Instead, you should remove the `include("Mymodule.jl")` in `Mymodule2.jl` and write `using ..Mymodule` on the following line.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [June 9, 2020, 4:26am UTC](https://discourse.julialang.org/t/how-to-define-function-input-type-a-struct-from-a-different-module/41031/3 "2020-06-09T04:26:21Z")

</div>

You might also find the discussion here relevant: [Error with modules sharing types](https://discourse.julialang.org/t/error-with-modules-sharing-types/37119)

---

<div class="post-metadata">

**Author:** ![Saad\_Mahmud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/saad_mahmud/32/15518_2.png) [@Saad\_Mahmud](https://discourse.julialang.org/u/Saad_Mahmud)\
**Post date:** [June 9, 2020, 6:29am UTC](https://discourse.julialang.org/t/how-to-define-function-input-type-a-struct-from-a-different-module/41031/4 "2020-06-09T06:29:32Z")

</div>

Thanks.

---

<div class="post-metadata">

**Author:** ![Saad\_Mahmud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/saad_mahmud/32/15518_2.png) [@Saad\_Mahmud](https://discourse.julialang.org/u/Saad_Mahmud)\
**Post date:** [June 9, 2020, 6:30am UTC](https://discourse.julialang.org/t/how-to-define-function-input-type-a-struct-from-a-different-module/41031/5 "2020-06-09T06:30:44Z")

</div>

The discussion on organizing module was really helpful. Thanks.
