# Module name, type name collision

**URL:** <https://discourse.julialang.org/t/module-name-type-name-collision/3012>\
**Category:** General Usage\
**Created:** [April 2, 2017, 5:31pm UTC](https://discourse.julialang.org/t/module-name-type-name-collision/3012 "2017-04-02T17:31:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Post date:** [April 2, 2017, 5:31pm UTC](https://discourse.julialang.org/t/module-name-type-name-collision/3012/1 "2017-04-02T17:31:18Z")

</div>

module A  
type A  
…  
end  
end

will give an error that A is being redefined.

I was just curious as to why. I expect it’s because it’s difficult to disambiguate in some situations.

Just curious and I couldn’t find any discussion of it.

It’s a kind of a useful convention, I find myself doing a lot of

module Name

type NameT  
…  
end  
end

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 2, 2017, 5:43pm UTC](https://discourse.julialang.org/t/module-name-type-name-collision/3012/2 "2017-04-02T17:43:29Z")

</div>

If you used the same name, how would the compiler know when to use which? Both types and modules are first-class objects.

You can use singular for the type, plural for the module. See [this guide](https://github.com/JuliaPraxis/Naming).

---

<div class="post-metadata">

**Author:** ![jwu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jwu/32/3775_2.png) [@jwu](https://discourse.julialang.org/u/jwu)\
**Post date:** [September 19, 2017, 3:03pm UTC](https://discourse.julialang.org/t/module-name-type-name-collision/3012/3 "2017-09-19T15:03:29Z")

</div>

the singular for type and plural for module strategy works for most of the time, but what if the type should also be plural?

such as:

```julia
type Points 
    xs::Vector{UInt32}
    ys::Vector{UInt32}
    zs::Vector{UInt32}
end 

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 19, 2017, 3:36pm UTC](https://discourse.julialang.org/t/module-name-type-name-collision/3012/4 "2017-09-19T15:36:47Z")

</div>

Then you have to come up with a different name for the module.

---

<div class="post-metadata">

**Author:** ![jwu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jwu/32/3775_2.png) [@jwu](https://discourse.julialang.org/u/jwu)\
**Post date:** [September 21, 2017, 2:46am UTC](https://discourse.julialang.org/t/module-name-type-name-collision/3012/5 "2017-09-21T02:46:09Z")

</div>

works, but still do not sounds beautiful!

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 21, 2017, 9:49am UTC](https://discourse.julialang.org/t/module-name-type-name-collision/3012/6 "2017-09-21T09:49:16Z")

</div>

> [@jwu](#):
>
> works, but still do not sounds beautiful!

I don’t understand your point. If you have two objects that share a namespace, and you want to be able to distinguish them, they have to have different names — there is no way around this. You may find this useful for choosing good names:

> **[GitHub - JuliaPraxis/Naming: Best Practices: choosing and using names](https://github.com/JuliaPraxis/Naming)**
>
> Best Practices: choosing and using names. Contribute to JuliaPraxis/Naming development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![jwu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jwu/32/3775_2.png) [@jwu](https://discourse.julialang.org/u/jwu)\
**Post date:** [September 22, 2017, 4:26pm UTC](https://discourse.julialang.org/t/module-name-type-name-collision/3012/7 "2017-09-22T16:26:41Z")

</div>

thanks. This might be a Julia design question. python makes the file name as module name, that might be a better design.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 22, 2017, 4:30pm UTC](https://discourse.julialang.org/t/module-name-type-name-collision/3012/8 "2017-09-22T16:30:55Z")

</div>

It is conventional to do the same in Julia, too; eg `PkgDev.generate` will set up

```julia
module Name
## ...
end

```

in `src/Name.jl`.

Nevertheless, I don’t see what this has to do with your original question (module vs type name).

---

<div class="post-metadata">

**Author:** ![malmaud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/malmaud/32/29_2.png) [@malmaud](https://discourse.julialang.org/u/malmaud)\
**Post date:** [September 22, 2017, 8:36pm UTC](https://discourse.julialang.org/t/module-name-type-name-collision/3012/9 "2017-09-22T20:36:55Z")

</div>

There has been discussion of doing this in Julia too, so that if you do `using X`, the content of `X.jl` will automatically be wrapped in a module called `X`.
