From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA00888; Sun, 30 Mar 2003 22:51:16 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA01081 for ; Sun, 30 Mar 2003 22:51:15 +0200 (MET DST) Received: from mons.uio.no (mons.uio.no [129.240.130.14]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h2UKpA524959 for ; Sun, 30 Mar 2003 22:51:10 +0200 (MET DST) Received: from itherther.simula.no ([129.240.228.187]) by mons.uio.no with esmtp (Exim 2.12 #7) id 18zjlX-0006LB-00 for caml-list@pauillac.inria.fr; Sun, 30 Mar 2003 22:50:56 +0200 Received: from hans by itherther.simula.no with local (Exim 3.36 #1) id 18zjlX-0004Nw-00 for caml-list@pauillac.inria.fr; Sun, 30 Mar 2003 22:50:55 +0200 To: caml-list@pauillac.inria.fr Subject: [Caml-list] Modules as compilation units From: Hans Ole Rafaelsen Date: 30 Mar 2003 22:50:55 +0200 Message-ID: <3azof3sbmts.fsf@itherther.simula.no> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam: no; 0.00; rafaelsen:01 simula:01 figuring:01 val:01 foo:01 foobar:01 struct:01 mli:01 sig:01 int:01 modules:02 unbound:02 module:03 unit:03 interface:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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