From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q47IFxcu017951 for ; Mon, 7 May 2012 20:15:59 +0200 X-IronPort-AV: E=Sophos;i="4.75,545,1330902000"; d="scan'208";a="157090552" Received: from walapai.inria.fr ([128.93.30.24]) by mail1-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 07 May 2012 20:15:54 +0200 Received: from walapai.inria.fr (localhost [127.0.0.1]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q47IFsTI017948 for ; Mon, 7 May 2012 20:15:54 +0200 Received: (from sympa@localhost) by walapai.inria.fr (8.13.6/8.12.10/Submit) id q47IFrjK017946 for caml-list@inria.fr; Mon, 7 May 2012 20:15:53 +0200 Date: Mon, 7 May 2012 20:15:53 +0200 X-Authentication-Warning: walapai.inria.fr: sympa set sender to sympa@inria.fr using -f To: caml-list@inria.fr From: coste@irit.fr In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: [Caml-list] reuse of abstract types Hello, While using the module system to abstract types, I often encounter the problem to reuse in a signature an abstract type declared in another signature. Let's take an example. I have a module M, which declares an abstract type t, with operations using this type. module type MT = sig type t val f : t -> .... end Now I want to design a module Q, with operations using type t. To refer to t in the signature of Q, I am obliged to declare a module Mt : MT inside the signature module type QT = sig module Mt : MT val g : Mt.t -> .... end Now the module M itself, before Q, because of sharing constraint in Q: module M : MT = struct type t = int let f x = .... end And finally the module Q, which must contain a module Mt to respect its signature: module Q : (QT with type Mt.t = M.t) = struct module Mt = M let g x = .... end As generally my modules are functors I will probably rather write the module QF: module QF (Mx:MT) : (QT with type Mt.t = Mx.t) = struct module Mt = Mx let g x = ... end And finally instanciate QF: module Q2 = QF (M) The declaration of Mt in QT and QF is here only to reference the type t. It seems natural that QF be parameterized by Mx:MT as it will certainly use operations of M, but what seems artificial is the declaration of Mt in the signature QT (and hence in the functor QF). Intuitively, I would say that the signature QT refers to the type t declared in the signature MT, not in the structure M. Is there a simpler way to do this ? I suspect my solution is too complicate, but I couldn't find better...