[ocaml-platform] on the need and design of OCaml namespaces
Leo White
lpw25 at cam.ac.uk
Tue Feb 26 17:03:28 GMT 2013
On Feb 26 2013, Yaron Minsky wrote:
>Leo, do you have a summary of what you don't like about Alain's
>namespace proposal? I'm not presently able to identify any obvious
>weaknesses in it.
I have a few of issues with Alain's proposal specifically, and then a
second group of issues that are with that kind of proposal in general (i.e.
defining the namespace separately from the modules it contains).
Issues with Alain's proposal specifically:
1. Alain's proposal does not include a notion of opening a namespace. The
ability to only open a namespace when actually using it (e.g. a local
open) would be very useful. For example, this means that the proposal
provides no assistance for handling multiple standard libraries in the
same program: you can either make "List" equal "Core_List" everywhere or
you can make it equal "Stdlib_List" everywhere. I see no real reason
why Alain's namespaces could not be extended with a namespace opening
feature.
2. Alain's proposal provides no means of aliasing namespaces. Similar to
opening a namespace, it would be useful to be able to say "open
Core.Std as CS" and then refer to Core_Std_Mutex as "CS#Mutex"
3. Alain's proposal only supports a flat namespace. As I said before,
hierarchical namespaces are very useful in certain situations.
Obviously this criticism only makes sense if you first add the ability
to open namespaces. Again this feature could easily be added to Alain's
proposal.
Issues with this kind of proposal:
1. They require unique file names. This means that every file must become
"package_Module.ml" or "package_Subpackage_Module.ml".
2. A module's name depends on other files. A module's name (by which I
mean its namespaced name) depends on the ".ns" file, this could
definitely be confusing.
3. They require you to manage an ".ns" file. Not a major burden, but it is
one more place to look for errors. It also must be included in all
calls to the compiler.
4. To me they put the namespace information in the wrong place. A
component should define its own names, it should also not have to open
its own namespace.
I think that the first group of issues above are important, but the second
group of issues are of a more aesthetic nature. Also, if you want to
automatically open modules along with a namespace, then that is much easier
with centralised definition of the namespace.
As a side note, if people are okay with long filenames, why not support
having filenames like "core-std-mutex.mli" and then allow "open namespace
Core" and "open namespace Core#Std".
These could be treated as if there were automatically a "core.ns":
namespace Std = "core-std.ns"
and "core-std.ns":
module Mutex = "core-std-mutex.mli"
that were passed to any compiler invocation that had such files on its
search path.
More information about the Platform
mailing list