# How to use multiple levels of module?

**URL:** <https://discourse.julialang.org/t/how-to-use-multiple-levels-of-module/5899>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 15, 2017, 2:15am UTC](https://discourse.julialang.org/t/how-to-use-multiple-levels-of-module/5899 "2017-09-15T02:15:43Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![merl-dev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/merl-dev/32/96_2.png) [@merl-dev](https://discourse.julialang.org/u/merl-dev)\
**Post date:** [September 15, 2017, 5:10am UTC](https://discourse.julialang.org/t/how-to-use-multiple-levels-of-module/5899/3 "2017-09-15T05:10:24Z")

</div>

> <https://github.com/JuliaLang/julia/issues/3312>
>
> I might be ignorant of the scope rules for submodules, but why does this:
> 
> \`\`\` j…ulia
> module Amod
> type A
> end
> 
> type B
> a::A
> end
> end
> \`\`\`
> 
> work, while this:
> 
> \`\`\` julia
> module Amod
> type A
> end
> 
> module Bmod
> type B
> a::A
> end
> end
> end
> \`\`\`
> 
> gives \`ERROR: A not defined\`?

> <https://stackoverflow.com/questions/40310787/julia-code-encapsulation-is-this-a-generally-good-idea/40314833#40314833>

> [@Scope of submodules](https://discourse.julialang.org/t/scope-of-submodules/2806):
>
> Say I have a module A, in which I define a constant. I would like to be able to use that constant in submodules of that module: module A a = 2 module B f(x) = x\*a end module C g(x) = x\*a end end This does not work: A.B.f(3) UndefVarError: a not defined Clearly, I need to import a into each submodule, but that seems a bit annoying… Would there be a way to automatically inherit from the superscope, possibly with a submodule keyword?

---

_[View the full topic](https://discourse.julialang.org/t/how-to-use-multiple-levels-of-module/5899)._
