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
Syntactic inclusion of in ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-04-09 (13:21)
From: Sébastien Hinderer <Sebastien.Hinderer@e...>
Subject: Re: Syntactic inclusion of in ?
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 in syntactically, it's not to work
with small files, but rather, becuse the code in is
automatically generated by a script, by parsing a C source file.

The C source code contains something like :

typedef enum {
} e;

The script produces the file, which contains:

| A
| B
| ...
| Z

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

type t =
#include ""

Thans a lot to those who already replied.


> 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:
> -- ----
> let foo = 1
> ------------
> -- ----
> 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]