[ocaml-platform] on the need and design of OCaml namespaces

Leo White lpw25 at cam.ac.uk
Fri Feb 22 17:10:39 GMT 2013


>> It's not evident to me that namespaces actually solve the problem either,
>they just seem to push the problem in the build system. The actual problem
>seems very related to the problem of hygienic macros (accidental name
>capture).
>
>Indeed.
>

There is also another issue using language extensions which namespaces 
solve. When you write a language extension to produce code that calls your 
library, you need to have it produce calls like:

  Foo.Comp.func ()

where Foo is the packed module that your library produces.

However, then you cannot use the syntax extension within your library 
because the Foo module does not exist yet.

This is why, for example, COW's quotations need command-line arguments to 
tell them whether they are inside COW or not.

More generally, packed modules create two different names for a module, one 
used within the other packed modules, and one used externally. Namespaces 
can simply avoid this problem because not all modules in the namespace need 
to exist before the namespace can be used.

>"Let's add this new feature
>so that this problem with that ugly tool can be partially fixed in this
>ugly way" is not going to fly.

I actually think that long names are a perfectly valid solution for hygene, 
rather than an ugly one. I can also think of at least 4 other problems that 
namespaces solve:

1. Grouping modules without using "pack". 
2. Providing multiple names for modules (e.g. "Core.Std.List" and 
   "Platform.List").
3. The circular naming problem described above. 
4. Control of the default set of names that are open when compiling a 
   module.

All of which are of obvious benefit to the platform (which is what we are 
discussing on this list).



More information about the Platform mailing list