Module name, type name collision


module A
type A


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



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.


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:

type Points 


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


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:


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


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

module Name
## ...

in src/Name.jl.

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


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.