[ocaml-platform] Followup to Leo's proposal
Leo White
lpw25 at cam.ac.uk
Wed Mar 13 13:53:53 GMT 2013
> One point I'd like to understand better in Leo's proposal (and related ones) in particular is how the following code
> would be interpreted:
>
>
> open namespace N1
> open namespace N2
> open namespace N3
>
> module X = Foo
>
> In which namespaces would module Foo be looked up for? One possibility would be to look it in:
>
> N1
> N2
> N1#N2
> N3
> N1#N3
> N1#N2#N3
>
> If this is the case, what would be the priority?
>
> Another possibility would be to decide upon the "open namespace N2" what N2 refers to (a toplevel namespace or a
> sub-namespace of N1). Is it the intention? What would be the criterion?
I think that there are two sane semantics for "open namespace
N". Using the description language from Gabriel's proposal, they are:
E' := E shallow merge right N
or
E' := E deep merge right N
where E is the old environment and E' is the new environment.
The first semantics corresponds to deciding upon the "open namespace N2"
which namespace N2 refers to and then only open that one. The second
semantics corresponds to searching for the "Foo" in your example by
looking for:
N1#N2#N3#Foo
N2#N3#Foo
N1#N3#Foo
N3#Foo
N1#N2#Foo
N2#Foo
N1#Foo
Foo
Note that modules must use the first semantics because their definitions
are closed, but since namespaces are open they are free to choose either
semantics.
I think that the best choice is to use the first semantics since it is
simpler. This is equivalent to closing the definitions of namespaces
within a particular source file. This makes sense since there is no real
benefit to leaving them open.
More information about the Platform
mailing list