From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: Tom Hawkins <tom@confluent.org>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Nesting Modules
Date: Wed, 02 Nov 2005 15:36:16 +0100 [thread overview]
Message-ID: <1130942176.4327.50.camel@localhost.localdomain> (raw)
In-Reply-To: <4368C6F4.6050301@confluent.org>
Sorry, but this is not a good solution. The leaves are only hidden from
the user, but can still cause nameclashes. (E.g. if one adds another
Leaf1 module later.)
The proper solution is to use -pack (and -for-pack in O'Caml 3.09):
ocamlc -o branch2.cmo -pack leaf2.cmo leaf3.cmo
ocamlc -o branch1.cmo -pack leaf1.cmo brachch2.cmo
Then throw away leaf*.{cmi,cmo} and branch2.{cmi,cmo}. Everything is now
in branch1.{cmi,cmo}.
For O'Caml 3.09 and ocamlopt, you need to add the right -for-pack
options, e.g.
ocamlopt -for-pack Branch1.Branch2 -c leaf2.ml
ocamlopt -for-pack Branch1.Branch2 -c leaf3.ml
ocamlopt -for-pack Branch1 -c leaf1.ml
ocamlopt -o branch2.cmx -pack -for-pack Branch1 leaf2.cmx leaf3.cmx
ocamlopt -o branch1.cmx -pack leaf1.cmx branch2.cmx
For O'Caml 3.08 and ocamlopt, you need GNU objcopy, but no extra
-for-pack options.
Gerd
Am Mittwoch, den 02.11.2005, 08:02 -0600 schrieb Tom Hawkins:
> I found a convenient way to compose a set modules into a hierarchical
> library. First define the set of modules (ml/mli file pairs) -- these
> become the leaves in the module tree. Next, define the branch modules
> in the hierarchy using "module Leaf = Leaf" (ml only, no mli). Then
> compile and link. The only restriction is that all functional code must
> reside in leaf modules. Here's an example...
>
> # Define the leaf modules.
> echo 'let name = "leaf1"' > leaf1.ml
> echo 'val name : string' > leaf1.mli
> echo 'let name = "leaf2"' > leaf2.ml
> echo 'val name : string' > leaf2.mli
> echo 'let name = "leaf3"' > leaf3.ml
> echo 'val name : string' > leaf3.mli
>
> # Define the branch modules.
> echo 'module Leaf2 = Leaf2;; module Leaf3 = Leaf3' > branch2.ml
> echo 'module Leaf1 = Leaf1;; module Branch2 = Branch2' > branch1.ml
>
> # Compile all leaf modules.
> ocamlc -c leaf1.mli
> ocamlc -c leaf1.ml
> ocamlc -c leaf2.mli
> ocamlc -c leaf2.ml
> ocamlc -c leaf3.mli
> ocamlc -c leaf3.ml
>
> # Compile all branch modules.
> ocamlc -c branch2.ml
> ocamlc -c branch1.ml
>
> # Link the library.
> ocamlc -a -o branch1.cma leaf1.cmo leaf2.cmo leaf3.cmo branch2.cmo
> branch1.cmo
>
> # Delete all *.cmi files except top.
> rm leaf*.cmi
> rm branch2.cmi
>
> # Run.
> ocaml branch1.cma
>
> Objective Caml version 3.09.0
>
> # Branch1.Branch2.Leaf3.name;;
> - : string = "leaf3"
>
>
>
>
> Thanks for everyone's help!
>
> -Tom
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
--
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany
gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de
Telefon: 06151/153855 Telefax: 06151/997714
------------------------------------------------------------
next prev parent reply other threads:[~2005-11-02 14:36 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-01 16:59 Tom Hawkins
2005-11-02 1:39 ` [Caml-list] " Pietro Abate
2005-11-02 6:43 ` Martin Jambon
2005-11-02 1:45 ` Robert Roessler
2005-11-02 2:03 ` Chris King
2005-11-02 8:42 ` Daniel Bünzli
2005-11-02 12:00 ` Tom Hawkins
2005-11-02 12:09 ` Daniel Bünzli
[not found] ` <Pine.LNX.4.62.0511011028340.4466@ganymede.cs.unm.edu>
2005-11-02 4:47 ` Tom Hawkins
2005-11-02 9:46 ` Richard Jones
2005-11-02 9:57 ` Daniel Bünzli
2005-11-02 10:47 ` Richard Jones
2005-11-02 10:57 ` Daniel Bünzli
2005-11-02 11:27 ` Richard Jones
2005-11-02 11:59 ` Tom Hawkins
2005-11-02 12:33 ` Richard Jones
2005-11-02 13:11 ` Christophe TROESTLER
2005-11-02 14:02 ` Tom Hawkins
2005-11-02 14:36 ` Gerd Stolpmann [this message]
2005-11-02 13:34 ` Oliver Bandel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1130942176.4327.50.camel@localhost.localdomain \
--to=info@gerd-stolpmann.de \
--cc=caml-list@yquem.inria.fr \
--cc=tom@confluent.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox