From: Hans Ole Rafaelsen <hans@simula.no>
To: caml-list@pauillac.inria.fr
Subject: [Caml-list] Modules as compilation units
Date: 30 Mar 2003 22:50:55 +0200 [thread overview]
Message-ID: <3azof3sbmts.fsf@itherther.simula.no> (raw)
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
next reply other threads:[~2003-03-30 20:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-03-30 20:50 Hans Ole Rafaelsen [this message]
2003-03-31 7:19 ` Ville-Pertti Keinonen
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=3azof3sbmts.fsf@itherther.simula.no \
--to=hans@simula.no \
--cc=caml-list@pauillac.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