caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Sébastien Hinderer" <Sebastien.Hinderer@ens-lyon.org>
To: caml-list@yquem.inria.fr, caml-list@inria.fr
Subject: Re: Syntactic inclusion of a.ml in b.ml ?
Date: Sat, 9 Apr 2005 15:20:26 +0200	[thread overview]
Message-ID: <20050409132026.GA3353@galois> (raw)
In-Reply-To: <20050409103532.GA20625@furbychan.cocan.org>

Dear Richard, dear all,

> I'm not 100% clear on what you want to do.

Sorry, I'll try to be more precise.

If I would like to incluee a.ml in b.ml syntactically, it's not to work
with small files, but rather, becuse the code in a.ml is
automatically generated by a script, by parsing a C source file.

The C source code contains something like :

typedef enum {
  A,
  B,
  ...,
  Z
} e;

The script produces the a.ml file, which contains:

| A
| B
| ...
| Z

And then I would like to be able to do something like this in b.ml :

type t =
#include "a.ml"

Thans a lot to those who already replied.

Cheers,
Sébastien.



> 
> 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
> 


  reply	other threads:[~2005-04-09 13:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-08 17:41 Sébastien Hinderer
2005-04-09 10:35 ` [Caml-list] " Richard Jones
2005-04-09 13:20   ` Sébastien Hinderer [this message]
2005-04-09 14:45     ` [Caml-list] " Radu Grigore
2005-04-09 15:49       ` Sébastien Hinderer
2005-04-09 21:15         ` [Caml-list] " Radu Grigore
2005-04-09 17:51   ` [Caml-list] " Robert Roessler
2005-04-09 21:27     ` William D.Neumann
2005-04-10 16:53     ` Richard Jones
2005-04-09 11:55 ` Olivier Andrieu
2005-04-09 12:54 ` sejourne_kevin
2005-04-09 21:16 ` Martin Jambon

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=20050409132026.GA3353@galois \
    --to=sebastien.hinderer@ens-lyon.org \
    --cc=caml-list@inria.fr \
    --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).