[ocaml-platform] Followup to Leo's proposal

Alain Frisch alain.frisch at lexifi.com
Thu Mar 14 11:17:11 GMT 2013


On 03/14/2013 11:46 AM, Yaron Minsky wrote:
> I don't fully understand why you want N#M to refer only to compilation
> units --- I suspect it's connected to implementation issues around
> things like ocamldep

That's one reason, but more fundamentally: namespaces are attached to 
compilation unit (you can define what the namespace of a compilation 
unit is) not to inner modules (you cannot put an inner module in a 
namespace) or other components of units (there is no namespace attached 
to a type or value declaration).  And it seems quite natural to me that 
the notation N#M resolves to something whose local name is M and whose 
namespace is N.  I think it's good to keep the qualified syntax very 
explicit and simple.  I'm less shocked if "open namespace N" brings in 
scope other modules and values by automatically opening some modules 
declared as "auto-open" in the definition of N.

In a previous post, I've mentioned a different approach of attaching 
namespaces not (only) to compilation units, but also to all declared 
components (i.e. make the "namespace" a property of local names).  This 
would allow writing things like:

module Baz#M = struct
   let Foo#x = 3

   let Bar#x = 2

   let Baz#x =
     let open namespace Foo in
     x + Bar#x
end

let a = Baz#M.Baz#x + Baz#M.Foo#x
let b = let open namespace Baz in M.x + M.Foo#x

(with some syntax to automatically put all declarations under a given 
scope into a given namespace)

What I like with this approach is that it makes namespaces appear more 
orthogonal to the module system (but since we would also need to attach 
namespace to compilation units, this does not solve any problem by 
itself).  And I don't see any practical use for this system either!


-- Alain


More information about the Platform mailing list