# Multiple files per module

**URL:** https://discourse.julialang.org/t/multiple-files-per-module/7007
**Category:** General Usage
**Tags:** question
**Created:** [November 11, 2017, 2:28pm UTC](https://discourse.julialang.org/t/multiple-files-per-module/7007 "2017-11-11T14:28:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [November 11, 2017, 2:28pm UTC](https://discourse.julialang.org/t/multiple-files-per-module/7007/1 "2017-11-11T14:28:27Z")

</div>

I want to split a module into multiple files. Should I put the module declaration:

```julia
module MyModuleName
...
end # module

```

in all the files?

---

<div class="post-metadata">

### Author: ![yurivish](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yurivish/32/307_2.png) [@yurivish](https://discourse.julialang.org/u/yurivish)
#### Post date: [November 11, 2017, 2:31pm UTC](https://discourse.julialang.org/t/multiple-files-per-module/7007/2 "2017-11-11T14:31:53Z")

</div>

You should have a single file with the module declaration and `include("file.jl")` inside it for each file you need. You can think of `include` as the equivalent of copy and pasting the contents of the included files into the place they were included (edit: not quite right, see below).

---

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [November 11, 2017, 2:32pm UTC](https://discourse.julialang.org/t/multiple-files-per-module/7007/3 "2017-11-11T14:32:17Z")

</div>

Thanks.

---

<div class="post-metadata">

### Author: ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)
#### Post date: [November 11, 2017, 3:15pm UTC](https://discourse.julialang.org/t/multiple-files-per-module/7007/4 "2017-11-11T15:15:38Z")

</div>

> [@yurivish](#):
>
> You can think of include as the equivalent of copy and pasting the contents of the included files into the place they were included.

This is not quite right. Expressions in an `include`d file are evaluated in the global scope of the current module. So inclusion works as expected for defining types and top-level functions, but not for local variable bindings. (The documentation is a bit misleading.)

Example: if file “h1.jl” has

```julia
a=3

```

then

```julia
julia> let b=4
       include("h1.jl")
       global f
       f(x) = a+b*x
       end
f (generic function with 1 method)

julia> b
ERROR: UndefVarError: b not defined

julia> a
3

```

and you get all the “benefits” of global variables:

```julia
julia> @code_typed(f(4))
CodeInfo(:(begin 
        return Main.a + (Base.mul_int)($(QuoteNode(4)), x)::Int64
    end))=>Any

```
