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

Alain Frisch alain.frisch at lexifi.com
Thu Feb 28 13:02:51 GMT 2013


On 02/28/2013 10:01 AM, Erkki Seppala wrote:
> While C++ might not be the golden standard to look upon on language
> development, perhaps it can serve as an inspiration. Its namespace
> system seems to work pretty nicely without complaints from the
> developers. It has the following constructs:

FWIW, this seems very similar to .Net.

It is interesting to see how this could be transposed more directly to 
OCaml.  This would change the current understanding that namespaces 
should control the name of compilation units.  Instead, every components 
created in a unit (sub-module, value, type) would be attached to a 
namespace, and a single compilation unit could export values/types/etc 
in different namespaces.

We could have a module exporting:

type Namespace1#foo = ...
val Namespace2#bar: string
module Namespace2#SubModule : sig ... end

probably with some syntax to factorize those prefixes:

namespace Namespace1 {
   type foo = ...
}

and ways to "open" namespaces ("using ...") and alias them.

This is really about attaching a "namespace" to every named component in 
structures/signatures.  (And we would need ways to define the namespace 
attached to a compilation unit.)

I don't see something like that happening for OCaml, though, because the 
overlap between this kind of namespaces and modules would be huge.


-- Alain


More information about the Platform mailing list