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 RAA24631 for caml-redistribution; Wed, 20 Mar 1996 17:39:28 +0100 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 PAA21457 for ; Wed, 20 Mar 1996 15:19:19 +0100 Received: from margaux.inria.fr (margaux.inria.fr [128.93.8.2]) by concorde.inria.fr (8.7.1/8.7.1) with ESMTP id PAA22687 for ; Wed, 20 Mar 1996 15:19:02 +0100 (MET) Received: from gr6.u-strasbg.fr (gr6.u-strasbg.fr [130.79.6.86]) by margaux.inria.fr (8.6.10/8.6.6) with SMTP id PAA27197 for ; Wed, 20 Mar 1996 15:19:18 +0100 Received: by gr6.u-strasbg.fr (4.1/SMI-3.2-jjp/4/6/92) id AA21602; Wed, 20 Mar 96 15:23:42 +0100 Date: Wed, 20 Mar 96 15:23:42 +0100 From: boos@gr6.u-strasbg.fr (Christian Boos) Message-Id: <9603201423.AA21602@gr6.u-strasbg.fr> To: Jocelyn Serot Cc: caml-list@margaux.inria.fr Subject: Re: Module system and separate compilation In-Reply-To: <199603190931.KAA11239@nez-perce.inria.fr> References: <199603190931.KAA11239@nez-perce.inria.fr> Sender: weis [French translation below] Hello, Here's some comments about your questions : Jocelyn Serot writes: > > (...) > (* file "bar.ml": *) > > module type Foo = sig type t val one : t val add : t -> t -> t end > module type Bar = sig type t val one : t val double : t -> t end > > module MakeBar(M: Foo) = (struct > type t = M.t > let one = M.one > let double x = M.add x x > end : Bar) > > (...) > > (* file bar.mli *) > > module type Bar = sig > type t > val one : t > val double : t -> t > end [1] This is the right way. To do the best, you should add : 'module type Foo = sig ... end ' and 'module MakeBar (M : Foo) : Bar' in the file "bar.mli". > > But this seems contradictory with the fact that, as stated in node2.12 of > CSL html manual > > "A compilation unit behaves roughly as the module definition > module unit-name : sig unit-interface end = struct unit-implementation end" > [2] There's no contradiction. In the file "foo.mli", a module Foo is implicitly declared. This module has type 'sig type t val one ... end' which is a sort of "anonymous" module type. In no way have you declared a module type named Foo, as expected in the "bar.ml" file. > Am i missing sth important, or even misusing the module system ?.. > In particular, the need for textual duplication of the Foo and Bar signatures > (which have written and compiled in separate files) in the file defining > the functor seems a bit annoying.. [3] I agree with you that this duplication is annoying. It's only justification is that a 'module type XXX = sig ... end' statement in a .mli is a module type declaration, and that the same statement in a .ml is a module type definition. This allows one to define abstract module types, for example. I suggest that the compiler be modified to automatically generate module type definition from module type declaration when this declaration is not an abstract one. This would eliminate the need for duplication in most cases. -- Christian Boos. ------------------------------------------------------------------ Bonjour, Je peux faire quelques commentaires sur vos questions. [1] C'est effectivement comme cela qu'il faut faire. Pour bien faire, il faudrait encore rajouter la déclaration du type de module 'module type Foo = sig ... end ' et celle foncteur 'MakeBar' dans le fichier bar.mli: module MakeBar (M : Foo) : Bar [2] Non, je ne vois pas la contradiction : le fichier "foo.mli" declare un module Foo, qui se trouve avoir un type (sig type t val one ... end), ce type n'étant pas nommé (il n'y a pas création de 'module type Foo = sig ... end'). [3] Oui, alors là d'accord. Le fait de devoir recopier les 'module type' dans les implémentations est pénible et source d'erreur. Cela se justifie parceque dans le .mli il s'agit de déclaration et dans le .ml d'une définition. Cette séparation permet par exemple de déclarer des types de modules abstraits ('module type Foo'). Mais la plus part du temps, il serait plus pratique de générer la définition à partir de la déclaration du .mli.