Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Tom Hawkins <tom@c...>
Subject: Re: [Caml-list] Nesting Modules
Daniel Bünzli wrote:
> e 2 nov. 05 à 03:03, Chris King a écrit :
> 
>> One way to do what you're looking to do, is to write in top.ml:
>>
>> 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' > bottom.ml
>  > echo 'module Bottom = Bottom' > top.ml
>  > ocamlc -c bottom.ml
>  > ocamlc -c top.ml
>  > 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).

Building a cma/cmxa is fine -- I am working on a library after all.  But 
for this to work, how are the mli files handled?  I tried several 
variations of the following, but again, I'm faced with "Unbound module 
type Bottom":

echo 'let hello = "hello"' > bottom.ml
echo 'val hello : string' > bottom.mli
echo 'module Bottom = Bottom' > top.ml
echo 'module type Bottom = Bottom' > top.mli
ocamlc -c bottom.mli
ocamlc -c bottom.ml
ocamlc -c top.mli
File "top.mli", line 1, characters 21-27:
Unbound module type Bottom

This must be a common problem.  Surely I'm not the first person 
constructing a hierarchical library.  OCaml claims to have a 
hierarchical module system, but I have yet to see an easy way to build a 
hierarchy of modules.  Am I really going to have to revert to a 
preprocessor?!?

-Tom