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
[Caml-list] Modules as compilation units
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-03-30 (20:51)
From: Hans Ole Rafaelsen <hans@s...>
Subject: [Caml-list] Modules as compilation units
Good evening,

I have some trouble figuring out how to get the module system and
separate compilation to work.  Given the following module definition
in the top-level:

module type FooBarSig = sig
  val foo : unit -> int
  val bar : unit -> int

module FooBar : FooBarSig = struct
  let foo () = 1
  let bar () = 2

module type BarSig = sig
  val bar : unit -> int

module Bar = (FooBar : BarSig)

(* Some usage testing *)
let _ =
- : int = 2
let _ =
- : int = 1
let _ =
Characters 8-15:
  let _ =;;
Unbound value

Works the way I want it to.

I can not find a way to organize the modules into separate files.  The
FooBar is simple,

val foo : unit -> int
val bar : unit -> int
let foo () = 1
let bar () = 2

but how do I make the Bar module.  My best attempt have been to make a
file called:
module type BarSig = sig
  val bar : unit -> int

module Bar = (FooBar : BarSig)

First of all it contains the signature inside a .ml file, which, well
I don't know, but I don't like it.  But the real problem is that the
bar method in the Bar module is packed inside another Bar module as a
result of the filename which the module is defined inside.
Thus it have to be accessed through:

Is there a way to generate the a module with only the bar method
visible, based on the FooBar module, and have this method directly
inside the Bar module?

What I want is something like:

val bar : unit -> int
(* Have no idea how to generate this module *)

I have spent quite some time searching documentation, but it seems
like these issues are mostly kept separate.  The module system is
discussed within the top-level, and then it is told how to do separate
compilation using .ml and .mli files, only using the most basic parts
of the modules system.  I.e a module and it's interface for
information hiding.  If anyone know of some documentation which
explains the relationship between modules and compilation units in
more depth, please let me know.

Kindest regards,

Hans Ole Rafaelsen

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: