caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Tom Hawkins <tom@confluent.org>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Nesting Modules
Date: Wed, 02 Nov 2005 06:00:41 -0600	[thread overview]
Message-ID: <4368AA69.4090504@confluent.org> (raw)
In-Reply-To: <BBC7B3DF-AA67-47D4-968F-41FBD87DC9F9@epfl.ch>

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




  reply	other threads:[~2005-11-02 11:19 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 [this message]
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
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=4368AA69.4090504@confluent.org \
    --to=tom@confluent.org \
    --cc=caml-list@yquem.inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).