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 (05:44)
From: Martin Jambon <martin_jambon@e...>
Subject: Re: [Caml-list] Nesting Modules
On Wed, 2 Nov 2005, Pietro Abate wrote:

> On Tue, Nov 01, 2005 at 10:59:27AM -0600, Tom Hawkins wrote:
>> Can I instruct the compiler to nest Bottom somewhere in Top, to obtain
>> clean, hierarchical names (eg: Top.Bottom.some_function)?  Of course I
>> can inline in, but then the file become rather large.
> There should be some way in camlp4 to inline files with and
> #include "" directive... Or at least I've a vague memory
> of this... I remember of a thread on this ml a while ago but I never
> use this trick. Does anybody can confirm this ?

Some time ago I wrote some code which works partially. You can 
include a file from within a submodule, i.e. you can do this:

   module A = struct USE "" end

The problem is line numbering. Setting Pcaml.input_file doesn't seem 
to have any effect. If anyone knows how to fix that please let me know:

(* camlp4o pa_extend.cmo q_MLast.cmo -loc loc *)

let parse_stream s =
   let f = !Pcaml.parse_implem in
   let rec loop () =
     match f s with
         l, true -> fst l @ loop ()
       | l, false -> fst l in
   loop ()

let parse_file file =
   let ic = open_in file in
   let stream = Stream.of_channel ic in
   let current_file = !Pcaml.input_file in
   Pcaml.input_file := file; (* it doesn't work *)
   let l = parse_stream stream in
   close_in ic;
   Pcaml.input_file := current_file;

   Pcaml.str_item: [
     [ "USE"; file = STRING ->
         let l = parse_file file in
         <:str_item< declare $list:l$ end >> ]



Martin Jambon, PhD
Freedom for the regexps!