Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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
end

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

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

module Bar = (FooBar : BarSig)

(* Some usage testing *)
let _ = Bar.bar()
- : int = 2
let _ = FooBar.foo()
- : int = 1
let _ = Bar.foo()
Characters 8-15:
  let _ = Bar.foo();;
          ^^^^^^^
Unbound value Bar.foo

Works the way I want it to.

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

fooBar.mli:
val foo : unit -> int
val bar : unit -> int

fooBar.ml:
let foo () = 1
let bar () = 2

but how do I make the Bar module.  My best attempt have been to make a
file called:

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

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 Bar.ml which the module is defined inside.
Thus it have to be accessed through:

Bar.Bar.bar()

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:

bar.mli:
val bar : unit -> int

bar.ml:
(* 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 caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners