Browse thread
Nesting Modules
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| 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 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).
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 = ...
end'.
Daniel