# Type definition works in the REPL, doesn't work in a module

**URL:** <https://discourse.julialang.org/t/type-definition-works-in-the-repl-doesnt-work-in-a-module/44515>\
**Category:** General Usage\
**Created:** [August 7, 2020, 5:37pm UTC](https://discourse.julialang.org/t/type-definition-works-in-the-repl-doesnt-work-in-a-module/44515 "2020-08-07T17:37:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![GlenHenshaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glenhenshaw/32/5269_2.png) [@GlenHenshaw](https://discourse.julialang.org/u/GlenHenshaw)\
**Post date:** [August 7, 2020, 5:37pm UTC](https://discourse.julialang.org/t/type-definition-works-in-the-repl-doesnt-work-in-a-module/44515/1 "2020-08-07T17:37:53Z")

</div>

I feel like I’m missing something basic here. The following code works when pasted in to the REPL:

```
using DataStructures: MutableLinkedList

module MyModule

   struct MapEntry{T<:Number, M, N}
      IC::Array{T,M}
      FC::Array{T,M}
      Vec::Array{T,N}
   end

   AssocMap = MutableLinkedList{MapEntry}
 end

```

I can then create variables of type AssocMap, which work as I expect. But when I put that same code in a module definition and include() the module file, I get the following error:

```
ERROR: LoadError: UndefVarError: MutableLinkedList not defined

```

pointing to that last line. Which means that the assoc = MutableLinkedList line is interpreted as a type definition when executed in the REPL, but as a variable instantiation when in a file?

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [August 7, 2020, 5:47pm UTC](https://discourse.julialang.org/t/type-definition-works-in-the-repl-doesnt-work-in-a-module/44515/2 "2020-08-07T17:47:07Z")

</div>

The only thing that makes sense to me is that you did not import `MutableLinkedList` in the context of that module.

---

<div class="post-metadata">

**Author:** ![GlenHenshaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glenhenshaw/32/5269_2.png) [@GlenHenshaw](https://discourse.julialang.org/u/GlenHenshaw)\
**Post date:** [August 7, 2020, 5:52pm UTC](https://discourse.julialang.org/t/type-definition-works-in-the-repl-doesnt-work-in-a-module/44515/3 "2020-08-07T17:52:43Z")

</div>

I did though. I’ll mod the OP.

---

<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:** [August 7, 2020, 5:59pm UTC](https://discourse.julialang.org/t/type-definition-works-in-the-repl-doesnt-work-in-a-module/44515/4 "2020-08-07T17:59:08Z")

</div>

Modules do not inherit variables from their parent scopes. This isn’t really about type definitions at all, but simply the fact that you cannot do:

```julia
julia> x = 1
1

julia> module Foo
         @show x
       end
ERROR: UndefVarError: x not defined
Stacktrace:
 [1] top-level scope at show.jl:641

```

Instead, you need to use `using` to bring any names from an outer module into the inner one:

```julia
julia> module Outer
         x = 1
         
         module Inner
           using ..Outer: x
           @show x
         end
       end
x = 1

```

---

<div class="post-metadata">

**Author:** ![GlenHenshaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glenhenshaw/32/5269_2.png) [@GlenHenshaw](https://discourse.julialang.org/u/GlenHenshaw)\
**Post date:** [August 7, 2020, 6:32pm UTC](https://discourse.julialang.org/t/type-definition-works-in-the-repl-doesnt-work-in-a-module/44515/5 "2020-08-07T18:32:49Z")

</div>

Yep, that’s it. Thanks!

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [August 7, 2020, 9:54pm UTC](https://discourse.julialang.org/t/type-definition-works-in-the-repl-doesnt-work-in-a-module/44515/6 "2020-08-07T21:54:30Z")

</div>

I should have been clearer. What `@rdeits` carefully explained was what I intended to mean.
