Re: Merging Modules

Mark Hayden (hayden@cs.cornell.edu)
Thu, 12 Sep 1996 09:16:01 -0400

Message-Id: <199609121316.JAA01731@verdandi.cs.cornell.edu>
To: caml-list@pauillac.inria.fr
Subject: Re: Merging Modules
Date: Thu, 12 Sep 1996 09:16:01 -0400
From: Mark Hayden <hayden@cs.cornell.edu>

>The Caml language does not support this. In Objective Caml, you can
>have several sub-modules in one input file, but still all the source
>code for the top module must reside in one source file.

I would find it useful if the name of the top module in the source file was
not determined by the file name. It would be nice if by default O'caml
used the file name as the name for a module, but allowed you to override
that with a different name. (This introduces problems because the
interface searching assumes the module name is the same as the .cmi file
name, but there are ways to get around this.)

Here is an example where this would be useful. I have a module x.mli for
which I've built several different implementations: x1.ml, x2.ml, x3.ml.
In order to compile each implementation with the module name X, I have to
(1) copy the module xi.ml to x.ml, (2) compile x.ml to x.cmo, and (3) copy
x.cmo to xi.cmo.

>A possibility is to compile each file as a distinct module (M1, M2, ...),
>then have one extra file/module M that re-exports what is made public
>to the remainder of the program, which then refers only to M. This is
>exemplified in the Caml Light user's manual, chapter on camllibr.

It would also be useful to allow several top level modules to reside in one
implementation file.... I'm thinking of cases where a lot of tiny modules
have to reside in separate files in order to use the O'caml module system.
Sometimes one would prefer to have the modules all in the same
implementation file (for instance, to improve compilation speed).

>Another possibility is to generate the module implementation from
>several input files in your Makefile, using "cat", "cpp", or whatever
>external tool does the job.
>
>Regards,
>
>- Xavier Leroy

Wouldn't it be better if O'caml included some mechanisms so that these
kinds of limitations didn't require hacks with cpp or cat to get around
them? I think O'caml is great as it is now, but a few additions to prevent
these problems would significantly improve it.

--Mark Hayden