caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Modules as compilation units
@ 2003-03-30 20:50 Hans Ole Rafaelsen
  2003-03-31  7:19 ` Ville-Pertti Keinonen
  0 siblings, 1 reply; 2+ messages in thread
From: Hans Ole Rafaelsen @ 2003-03-30 20:50 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Modules as compilation units
  2003-03-30 20:50 [Caml-list] Modules as compilation units Hans Ole Rafaelsen
@ 2003-03-31  7:19 ` Ville-Pertti Keinonen
  0 siblings, 0 replies; 2+ messages in thread
From: Ville-Pertti Keinonen @ 2003-03-31  7:19 UTC (permalink / raw)
  To: Hans Ole Rafaelsen; +Cc: caml-list

> bar.ml:
> (* Have no idea how to generate this module *)

How about:

bar.ml:
include FooBar

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-03-31  7:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-30 20:50 [Caml-list] Modules as compilation units Hans Ole Rafaelsen
2003-03-31  7:19 ` Ville-Pertti Keinonen

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