Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Nesting Modules
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-11-02 (08:42)
From: Daniel_Bünzli <daniel.buenzli@e...>
Subject: Re: [Caml-list] Nesting Modules
e 2 nov. 05 à 03:03, Chris King a écrit :

> One way to do what you're looking to do, is to write in
> module Bottom = Bottom
> This will essentially re-export Bottom in Top.  Unfortunately, this
> requires that you link bottom.cmo in with your code, which causes
> Bottom to be visible at the top level.

It will not be visible to the user if you don't provide bottom.cmi.  
The problem of linking can be alleviated by packing everything in a  
cma library. In other words what you can do is

 > echo 'let f x = x' >
 > echo 'module Bottom = Bottom' >
 > ocamlc -c
 > ocamlc -c
 > ocamlc -a -o toplib.cma bottom.cmo top.cmo
 > rm bottom.cmi
 > ocaml toplib.cma
         Objective Caml version 3.09.0

# Bottom.f;;
Unbound value Bottom.f
# Top.Bottom.f;;
- : 'a -> 'a = <fun>

When you want to link an executable using Top you now need to specify  
toplib.cma (instead of top.cmo).

Note that using 'include' poses the same problems of visibility and  
linking so you will have to adopt the same technique. In fact I think  
that 'module Bottom = Bottom' is exactly the same as 'module Bottom =  
struct include Bottom end', the former being more obvious. 'include'  
is only usefull if you need to extend the structure with new  
elements, e.g. 'module Bottom = struct include Bottom let g x = ...