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
1 Like
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 .
2 Likes
jwu
September 19, 2017, 3:03pm
3
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
xs::Vector{UInt32}
ys::Vector{UInt32}
zs::Vector{UInt32}
end
Then you have to come up with a different name for the module.
jwu
September 21, 2017, 2:46am
5
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:
jwu
September 22, 2017, 4:26pm
7
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
## ...
end
in src/Name.jl
.
Nevertheless, I don’t see what this has to do with your original question (module vs type name).
malmaud
September 22, 2017, 8:36pm
9
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
.