# Help with modules and types

**URL:** <https://discourse.julialang.org/t/help-with-modules-and-types/71782>\
**Category:** New to Julia\
**Tags:** module\
**Created:** [November 19, 2021, 2:05pm UTC](https://discourse.julialang.org/t/help-with-modules-and-types/71782 "2021-11-19T14:05:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cesarmarinhorj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cesarmarinhorj/32/30948_2.png) [@cesarmarinhorj](https://discourse.julialang.org/u/cesarmarinhorj)\
**Post date:** [November 19, 2021, 2:05pm UTC](https://discourse.julialang.org/t/help-with-modules-and-types/71782/1 "2021-11-19T14:05:29Z")

</div>

I am trying organize a simple module and submodules to learn Julia.

I made an HR module, with a submodule, Staff. Inside it, will have a age function, that has a Person as argument.  
the model in it first worked well with struct in same module, the Person struct.  
Now I wanna create a Model module, separated, to share it with others submodules, as necessary.

So, will be something like:  
HR → include Model, Staff  
HR → Model → struct Person  
HR → Staff → function age(p::Person)

but this dont works… age cant see Person correctly…

How can use Person from submodule Model and in any submodule?

Thanks!!!

---

<div class="post-metadata">

**Author:** ![mmiller](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmiller/32/20805_2.png) [@mmiller](https://discourse.julialang.org/u/mmiller)\
**Post date:** [November 19, 2021, 2:12pm UTC](https://discourse.julialang.org/t/help-with-modules-and-types/71782/2 "2021-11-19T14:12:19Z")

</div>

Hi @cesarmarinhorj ! How about something like this (I’ve assumed each module is in a separate script)

In `HR.jl`

```nohighlight
module HR

include("Model.jl")
using .Model # . means look in local scope rather than registry

include("Staff.jl")
using .Staff

end # module

```

In `Model.jl`

```nohighlight
module Model

struct Person
    age::Int
end

end # module

```

In `Staff.jl`

```nohighlight
module Staff

using ..Model # .. means look in scope of parent module

function age(p::Model.Person)
    return p.age
end

end # module

```

Alternatively `Person` could be exported from `Model` and then you could just use `Person` in `Staff`.

---

<div class="post-metadata">

**Author:** ![cesarmarinhorj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cesarmarinhorj/32/30948_2.png) [@cesarmarinhorj](https://discourse.julialang.org/u/cesarmarinhorj)\
**Post date:** [November 19, 2021, 2:15pm UTC](https://discourse.julialang.org/t/help-with-modules-and-types/71782/3 "2021-11-19T14:15:06Z")

</div>

Thanks!!! gonna try now!!!  
8)

---

<div class="post-metadata">

**Author:** ![cesarmarinhorj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cesarmarinhorj/32/30948_2.png) [@cesarmarinhorj](https://discourse.julialang.org/u/cesarmarinhorj)\
**Post date:** [November 19, 2021, 2:19pm UTC](https://discourse.julialang.org/t/help-with-modules-and-types/71782/4 "2021-11-19T14:19:24Z")

</div>

> [@mmiller](#):
>
> `using .Model`

Works!!! thanks too much!!!  
8)

---

<div class="post-metadata">

**Author:** ![mmiller](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmiller/32/20805_2.png) [@mmiller](https://discourse.julialang.org/u/mmiller)\
**Post date:** [November 19, 2021, 2:25pm UTC](https://discourse.julialang.org/t/help-with-modules-and-types/71782/5 "2021-11-19T14:25:16Z")

</div>

Great, you’re welcome!

As another point of reference, here is a great example of code written with submodules for a simple microservice:

[https://github.com/quinnj/MusicAlbums.jl/tree/master/src](https://github.com/quinnj/MusicAlbums.jl/tree/master/src)

---

<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:** [November 19, 2021, 2:27pm UTC](https://discourse.julialang.org/t/help-with-modules-and-types/71782/6 "2021-11-19T14:27:01Z")

</div>

Note that excessive use of submodules is sort of an anti-pattern in Julia (modules do not play the same role as they do in Python, for example).

Packages are generally “flat”, meaning having a single module and just “including” pieces of code, once, at the top of the module code. Something like:

```julia
module MyPackage

using Stuff

export f, g, h

include("./f.jl")
include("./g.jl") 
include("./h.jl")

end

```

where `f.jl` and others are just plain code files (without modules).
