From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id TAA04900 for caml-redistribution; Wed, 23 Oct 1996 19:59:24 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.6.10/8.6.6) with ESMTP id LAA23665 for ; Wed, 23 Oct 1996 11:29:27 +0200 Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.7.6/8.7.1) with ESMTP id LAA29567; Wed, 23 Oct 1996 11:29:27 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id LAA23661; Wed, 23 Oct 1996 11:29:26 +0200 From: Xavier Leroy Message-Id: <199610230929.LAA23661@pauillac.inria.fr> Subject: Re: type declaration in */mli & *.ml To: Basile.Starynkevitch@cea.fr (Basile STARYNKEVITCH) Date: Wed, 23 Oct 1996 11:29:26 +0200 (MET DST) Cc: caml-list@inria.fr In-Reply-To: <199610210923.LAA01989@soleil.serma.cea.fr> from "Basile STARYNKEVITCH" at Oct 21, 96 11:23:25 am MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: weis > It seems that when a type is declared in the interface of a module Moo > -ie in the file moo.mli- it should also be declared in the > implementation of the same module Moo -ie in the file moo.ml-. > I don't understand why is it so, and I feel such a redundancy is very > annoying. It's a pain, all right, but the explanation is very simple in terms of module interfaces (specifications) and module implementations. When a .mli file, or equivalently a sig ... end module type, contains type t = A of ... | B of ... that's just a specification saying that any implementation of this interface (that is, the .ml file or any structure that is matched against the interface) must define a type t with the same constructors and arguments. The type t could also be specified abstract, as in: type t in which case the implementation can define t as any constant type. In both cases, the implementation must provide a definition for t. Of course, if t is specified manifest, this does not leave much flexibility for the definition of t in the implementation, which is usually identical to the specification in the interface. When using the full module calculus, an implementation (struct...end) can have several interfaces (sig...end), and an interface can have several implementations, so it's not possible in general to have automatic definitions of types in the implementation based on the manifest declarations in the interface. > (perhaps I could paraphrase my question: does an implementation file > moo.ml of a module Moo contain an implicit open Moo;; ??) The answer is no, and this would not make sense, since "open" can only apply to an implementation, not an interface (again, there might be several implementations of a given interface), so you would be opening the implementation you're currently defining. - Xavier Leroy