open X ..... A.f 1 2; B.g "adsf" "xxx"; etc.This simple tool achieves this goal, at the loss of separate compilation of the X internals. The ideal solution is also supported, but it is slightly problematic with the current version of OCaml. First, I'll describe the ideal solution, then, the problem, and finally, the current workaround. The ideal solution works as follows. take modules A, B, and C, and create a file named X.ml that looks like this:
module A = A module B = B module C = CThen, a library (X.cma, or X.cmxa) containing A,B,C is created. The interface files a.mli, b.mli, and c.mli are agglomerated into x.mli. Files x.ml and x.mli are compiled and checked against each other. Applications can then compile against x.cmi, and link with x.{cma,cmxa}. There is a caveat: an application using x.cma may also link with its very own A,B, and C modules. This can cause havoc, because symbol names will overlap. The current version of OCaml does not resolve this. The work-around we currently have in place is to simply copy module bodies into x.ml. For example, we'll have:
module A = struct let f = .. let g = .. end module B = struct let a = .. let b = .. end module C = struct let x = .. endThis has the drawback that separate compilation for X is lost. However, it works!
The tool is named emrg. usage is as follows:
-o | direct the output to a file name |
-ml | merge ML files |
-mli | merge MLI files |
-copy | copy ML module bodies |
emrg can handle long path names, such as /A/B/zoo.ml. Note that when compiling the resultant library file (x.ml), provide ocamlc with the proper include paths. An example makefile is provided.
The complete package package (~3K).
Browse: Makefile Makefile.nt a.ml a.mli b.ml b.mli emrg.ml
Send support questions to Ohad Rodeh
Last modified: Thu Jan 10 06:30:38 EST 2002