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

Gabriel Scherer gabriel.scherer at gmail.com
Thu Feb 21 15:56:13 GMT 2013


How would one specify which search path is associated to a given namespace
path (eg. Core.Std)? Is it easy to integrate into ocamlfind?

On Thu, Feb 21, 2013 at 4:36 PM, Leo White <lpw25 at cam.ac.uk> wrote:

> Since about a year now, there has been a intermittent discussion ongoing
>> on the idea of introducing "namespaces" to the OCaml language[...], but
>> there have been fairly different ideas about how to best solve those
>> problems, or even what "namespace" means.
>>
>
> As I see it what we *need* from namespaces is fairly simple:
>
>  Developers must be able to give their components long (hierarchical)
>  names without changing the component's filename.
>
> This allows components with the same filename to coexist within the search
> path. It also allows these components to be grouped together without
> packing them into a single module.
>
> Any other features, such as allowing users to use multiple versions of a
> component or automatically assigning long names to components based on
> their position within the filesystem should be considered superfluous and
> unnecessary for an initial implementation.
>
>
> In practical terms, what we need (based on Fabrice's "namespaces" branch
> of the OCaml source tree) is to be able to start a file with a syntax like:
>
>  in Core.Std
>
> This path is then included in the .cmi file and other compiled files.
> Then, when a user writes "Core.Std.List", lookup proceeds as follows:
>
> 1. Look for a module called Core in the current local environment.
> 2. Look for a file "core.cmi" in the search path that is not attached to a
>   namespace.
>
> 3. Look for a file "std.cmi" in the search path that is attached to the
> "Core" namespace.
>
> 4. Look for a file "list.cmi" in the search path that is attached to the
> "Core.Std" namespace.
>
> This lookup scheme could be simplified by, as Gabriel has suggested, using
> a different separator for namespaces (e.g. Core#Std#List). Personally, I
> don't have a strong opinion either way. A new separator is less ambiguous,
> but it is one more piece of syntax for beginners to learn.
>
>
> Other simple features that would be useful include:
>
> - Opening namespaces  ("open Core.Std")
>
> - Aliasing namespaces  ("open Core.Std as CS")
>
> - Attaching a component to multiple namespaces ("in Core.Std and
>  Core.Containers")
>
> - A command-line option alternative to the "in" syntax.
>
> - A command-line option to pre-open namespaces.
>
> Regards,
>
> Leo
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ocaml.org/pipermail/platform/attachments/20130221/2f083c0b/attachment.html>


More information about the Platform mailing list