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 JAA27245; Tue, 11 Nov 2003 09:21:56 +0100 (MET) 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 JAA27618 for ; Tue, 11 Nov 2003 09:21:55 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hAB8Lr129324 for ; Tue, 11 Nov 2003 09:21:54 +0100 (MET) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3p2-20030924/3.7W) with ESMTP id RAA01795; Tue, 11 Nov 2003 17:21:48 +0900 (JST) To: chrisg@cs.uoregon.edu Cc: caml-list@inria.fr Subject: Re: [Caml-list] type issues with modules In-Reply-To: <3FB0749C.80103@cs.uoregon.edu> References: <3FB0749C.80103@cs.uoregon.edu> X-Mailer: Mew version 1.94.2 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20031111172147M.garrigue@kurims.kyoto-u.ac.jp> Date: Tue, 11 Nov 2003 17:21:47 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 jacques:01 mli:01 val:01 mli:01 val:01 ocamlc:01 ocamlc:01 struct:01 struct:01 recursion:01 dependencies:01 intentional:01 recursion:01 jacques:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Chris GauthierDickey > I have a weird issue, but I'm not sure if it's related to the type > system or what's really going on. I've boiled the problem down to the > simple case below. I have 4 files, two that are interfaces for the modules. > > file: mod1.mli > type t1 = T1 > val v: t1 > > file mod1.ml > type t1 = T1 > let v = Mod2.f2 () > > file mod2.mli > val f2: unit -> Mod1.t1 > > file mod2.ml > let f2 () = Mod1.T1 > > > I compile the files as such: > > ocamlc -g mod1.mli > ocamlc -g mod2.mli > ocamlc -g mod1.ml > > at which point I get the error: > The implementation mod1.ml does not match the interface mod1.cmi: > Values do not match: val v : Mod1.t1 is not included in val v: t1 Explanation: As specified in the reference manual, the combination of .ml and .mli is expected to mean: module type Sig_mod1 = sig end module Struct_mod1 = struct end module Mod1 : Sig_mod1 = Struct_mod1 This means that during the typing of the contents of mod1.ml, the compiler does not know yet that it is defining Mod1 (no recursion). As a result, the t1 in mod1.ml and the Mod1.t1 in mod2.mli are not known to represent the same type. Hence the error. Moreover, the possibility of creating mutual dependencies between modules by compiling a module against a .mli of another module depending on the first one is not intentional, and should probably not be relied upon. > P.S. I know I can move t1 into another module, but for software > engineering reasons, I don't want to do that. I'm wondering what you mean by software engineering reasons. That you want to keep types and values in the same module? Unfortunately, this does not work well with the absence of recursion between modules. Putting all types in a third module is indeed the simplest solution. Jacques Garrigue ------------------- 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