# How do I structure this correctly in my package?

**URL:** <https://discourse.julialang.org/t/how-do-i-structure-this-correctly-in-my-package/81726>\
**Category:** General Usage\
**Tags:** package\
**Created:** [May 26, 2022, 3:25pm UTC](https://discourse.julialang.org/t/how-do-i-structure-this-correctly-in-my-package/81726 "2022-05-26T15:25:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [May 26, 2022, 3:25pm UTC](https://discourse.julialang.org/t/how-do-i-structure-this-correctly-in-my-package/81726/1 "2022-05-26T15:25:25Z")

</div>

Hello!

I have made a small package here:

> **[GitHub - AhmedSalih3d/SPH\_jl](https://github.com/AhmedSalih3d/SPH_jl)**
>
> Contribute to AhmedSalih3d/SPH\_jl development by creating an account on GitHub.

In this package I have a folder structure such as:

```julia
- src
        - geometry.jl
        - main.jl
        - main_package.jl
        - math_vectors.jl

```

In which I try to split stuff into modules, because this is what I like from Rust.

Basically math\_vectors define some basic math functionality I want, geometry uses this functionality, main\_package bundles the two together and they are then called in main:

```julia
include("main_package.jl")
using .main_package

a = Vec(1.,2.,3.)
b = Vec(2.,4.,6.)

println(a + b)
println(a - b)
println(a / b)
println(a * b)

println(ℕ²(a))
println(ℕ(a))

v1 = Vec(0.,0.,0.)
v2 = Vec(1.,1.,1.)
vline = draw_line(v1,v2,0.4)
println(vline)

```

When I do like this it works fine to call “Vec”, but when I try to use “draw\_line” from geometry.jl:

```julia
ERROR: MethodError: no method matching draw_line(::Vec{Float64, Float64, Float64}, ::Vec{Float64, Float64, Float64}, ::Float64)
Closest candidates are:
  draw_line(::Main.geometry.math_vectors.Vec, ::Main.geometry.math_vectors.Vec, ::Number) at ~/.julia/dev/SPH_jl/src/geometry.jl:7
Stacktrace:
 [1] top-level scope
   @ ~/.julia/dev/SPH_jl/src/main.jl:18

```

Suddenly it does not accept “Vec” from “main space”, but wants a specific version. How do I fix this?

Kind regards

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [May 26, 2022, 3:50pm UTC](https://discourse.julialang.org/t/how-do-i-structure-this-correctly-in-my-package/81726/2 "2022-05-26T15:50:37Z")

</div>

The easiest way is not to split your package in modules but just use one main module that includes the other files.

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [May 26, 2022, 3:54pm UTC](https://discourse.julialang.org/t/how-do-i-structure-this-correctly-in-my-package/81726/3 "2022-05-26T15:54:56Z")

</div>

It sounds like the issue is that each `Module` defines its own function `draw_line`.  
What you probably intended was to add methods to a single function `draw_line`. That would work, for example, like this:

```julia
module A
  function foo(x :: Int) end
end

using .A

function A.foo(x :: Float64) end

# or
import A: foo
function foo(x :: Float64) end

end

```

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [May 26, 2022, 3:56pm UTC](https://discourse.julialang.org/t/how-do-i-structure-this-correctly-in-my-package/81726/4 "2022-05-26T15:56:10Z")

</div>

That is not the issue

Each module has some functionality, the functionality of math\_vectors need to present in both main and geometry. Then a conflict occurs in regards to the same type, one defined in main and one defined in the geometry file. That is what confuses me

Kind regards

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [May 26, 2022, 3:56pm UTC](https://discourse.julialang.org/t/how-do-i-structure-this-correctly-in-my-package/81726/5 "2022-05-26T15:56:28Z")

</div>

That works. But is that really the only way?

Kind regards

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 26, 2022, 4:05pm UTC](https://discourse.julialang.org/t/how-do-i-structure-this-correctly-in-my-package/81726/6 "2022-05-26T16:05:49Z")

</div>

It is the most practical way while the functionality of these modules does not justify a new package. When that happens, creating a new package is nice because then the dependency managing is taken care by the package manager. (Modules that are not packages are less useful in Julia than in other languages).
