[ocaml-platform] on the need and design of OCaml namespaces
Leo White
lpw25 at cam.ac.uk
Thu Feb 21 17:00:25 GMT 2013
On Feb 21 2013, Gabriel Scherer wrote:
>So in this case you would have to look for list.cmi, std.cmi then core.cmi
>(if you don't know which are namespaces, and which are actual compilation
>unit names).
I would probably look for core.cmi then std.cmi and then list.cmi, but
basically yes.
>One problem with this proposal is that the compiler has no knowledge of the
>set of "existing" namespaces. This combines very badly with the
>module/namespace syntactic ambiguity: when you write "open Lsit" (List,
>with a typo), the compiler will silently accept the opening of the Lsit
>namespace.
> [...]
>(Removing the syntactic ambiguity makes this slightly less of a problem,
>but it's still a pain to not be warned of namespace typos.)
Catching this error (without syntactic ambiguity) should not actually be
that hard in practise.
Consider something like "open Core#Sdt". This typo prevents us from finding
an appropriate .cmi file, because the namespace is Core#Std rather than
Core#Sdt. The unbound module error could include the fact that a .cmi file
was found but that its namespace was not open.
The compiler could even locate the unused "open Core#Sdt" and use the new
spell-checking code to suggest that it might be the cause of the error.
There is obviously still a risk that the typo in the open statement will
not cause an error because there is another .cmi with the same name whose
namespace is open. However, the "open Core#Sdt" instruction should still
raise an "unused open" warning.
Overall, I don't think that it is worth forcing users to pre-declare all
possible namespaces, just to avoid a slightly confusing error message in
the case of a typo.
Even if you decide that you need to pre-declare all namespaces it should
not be the responsibility of the user. It would be better to create special
".cmi" files to represent the namespaces. These would not contain any
information other than the name of their parent namespace, they would
simply exist to show that the namespace existed. This might also make it
easier to have namespaces and modules use the same seperator.
Leo
More information about the Platform
mailing list