Version française
Home     About     Download     Resources     Contact us    
Browse thread
Managing module names
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Paul Stodghill <stodghil@c...>
Subject: Managing module names
This is the message that I am going to send to Jason, Mark, and the Caml
mailing list. What do you think?

One of the things that modules in O'Caml can be used for is to prevent
namespace pollution. That is, functions and times encapsulated
within modules can be given names without fear that those names will
conflict with names in other modules.

But, how does one prevent pollution in the module namespace?

As near as I can tell, there are two ways to address this problem:

1) Carefully choose the names of the .ml and .mli files that will contain
   each of the top-level modules.

   E.g., Project_util, Project_expr, Project_toplevel

   The advantage of this approach is that each of these modules can go into
   its own source file and each can be compiled seperately. The
   disadvantage is that the module names tend to be longer, or less
   intuitive.

2) Enclose all of the "top-level" modules within a single "Project" module.

   E.g., Project.Util, Project.Expr, Project.Toplevel

   The advantage is that the names of the modules that are visible to the
   user of the Project module are more "rational", and the simpler names of
   the modules can be used simply by openning the Project module. The
   disadvantage seems to be that this requires some contortions in order to
   get this to work:

   Project.mli:
   module Util = Project_util
   module Expr = Project_expr
   module Toplevel = Project_toplevel

   Project_util.ml:
   (* implementation of the Project.Util module *)

   Project_expr.ml:
   (* implementation of Project.Expr module *)
   open Project_expr (* <- Yuck! *)
   ...

Here is my question: Are there other approach that people have used to
managing module name space pollution in O'Caml?

Thanks in advance.
-- 
Paul Stodghill <stodghil@cs.cornell.edu>
http://www.cs.cornell.edu/home/stodghil/home.html