From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 4A9AFBC48 for ; Sat, 9 Apr 2005 12:35:34 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j39AZXdt004191 for ; Sat, 9 Apr 2005 12:35:34 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA02631 for ; Sat, 9 Apr 2005 12:35:33 +0200 (MET DST) Received: from furbychan.cocan.org (furbychan.cocan.org [80.68.91.176]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j39AZWvU004187 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Sat, 9 Apr 2005 12:35:33 +0200 Received: from rich by furbychan.cocan.org with local (Exim 3.35 #1 (Debian)) id 1DKDJM-0007Tr-00 for ; Sat, 09 Apr 2005 11:35:32 +0100 Date: Sat, 9 Apr 2005 11:35:32 +0100 To: caml-list@inria.fr Subject: Re: [Caml-list] Syntactic inclusion of a.ml in b.ml ? Message-ID: <20050409103532.GA20625@furbychan.cocan.org> References: <20050408174142.GA1804@galois> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20050408174142.GA1804@galois> User-Agent: Mutt/1.3.28i From: Richard Jones X-Miltered: at concorde with ID 4257AFF5.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4257AFF4.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 gcc:01 ocamlc:01 cpp:01 -pp:01 compiler:01 ocaml:01 foo:01 'foo':01 'open:01 -pack:01 ocamlc:01 -pack:01 cmo:01 cmo:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: On Fri, Apr 08, 2005 at 07:41:42PM +0200, Sébastien Hinderer wrote: > (How) is it possible to include syntactically a file a.ml in a file > b.ml ? > > One method that seems to w)rk is to rename b.ml to b.ml.c, > and then have in b.ml.c a line saying > #include "a.ml" > And with this, gcc -E b.ml.c > b.ml > produces a file that ocamlc can apparently handle. I'm not 100% clear on what you want to do. A common requirement is to split a large module into a number of smaller files, which is then compiled back into a single large module. This can be done using a preprocessor (such as cpp) - see the -pp option to the compiler. Often it's better just to use a single large file and a capable editor, with "folding"[1] capabilities. Another one is to include the symbols from one module in another. This can be done using the 'include' directive in OCaml, eg: -- a.ml ---- let foo = 1 ------------ -- b.ml ---- include A let bar = 2 ------------ Now, if compiled in the correct order, module B will export symbols 'foo' and 'bar'. 'include' and 'open' are very similar. The difference is that 'include' causes the symbols imported to be (re-)exported. 'open A' on the other hand makes the symbols in A available inside B, but they are not exported in B's interface. Another option is to use the -pack argument when linking [not supported on all platforms]. This causes modules to be nested inside a "super-module". For example, ocamlc -pack -o c.cmo a.cmo b.cmo (IIRC) creates a module called C containing C.A and C.B modules. Rich. [1] http://www.moria.de/~michael/fe/folding.html -- Richard Jones, CTO Merjis Ltd. Merjis - web marketing and technology - http://merjis.com Team Notepad - intranets and extranets for business - http://team-notepad.com