From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 975C9BCAE for ; Wed, 6 Jul 2005 12:13:50 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j66ADnab015120 for ; Wed, 6 Jul 2005 12:13:49 +0200 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 MAA24500 for ; Wed, 6 Jul 2005 12:13:49 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j66ADlbY015117 for ; Wed, 6 Jul 2005 12:13:48 +0200 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id j66ADc3f013457; Wed, 6 Jul 2005 19:13:39 +0900 (JST) Date: Wed, 06 Jul 2005 19:13:36 +0900 (JST) Message-Id: <20050706.191336.45516355.garrigue@math.nagoya-u.ac.jp> To: Pietro.Abate@anu.edu.au Cc: caml-list@inria.fr Subject: Re: [Caml-list] class type inside a sig From: Jacques Garrigue In-Reply-To: <20050706092010.GA26758@pulp.anu.edu.au> References: <20050706092010.GA26758@pulp.anu.edu.au> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 42CBAEDD.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 42CBAEDB.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 sig:01 anu:01 sig:01 val:01 struct:01 mismatch:01 val:01 ocaml:01 ocaml:01 cvs:01 functor:01 ...:98 inherit:01 constructor:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: From: Pietro Abate > how can I pass a generic class type inside a signature without > actually specifying the class itself ? > > this is the best I figured out : > > module type S = > sig > type c = < add : int -> 'c > as 'c > val make : unit -> c > end > > module Make ( T:S ) = struct > > (* let init = new T.c *) > let init = T.make () > let add e = init#add e > > end > > but it isn't satisfactory as I've to pass a 'make' function and This is somehow unavoidable: if you want your class type to be generic, then you cannot be sure that its constructor will have the right type. So it is more natural to pass it independently. > if I try to instantiate the module with a super class of c, it gives > me a signature error. [...] > Signature mismatch: > Modules do not match: > sig class c : test val make : unit -> test end > is not included in > S > Type declarations do not match: > type c = < add : int -> c; other : int > > is not included in > type c = < add : int -> 'a > as 'a > > how can I achieve this ? > > Basically I'd like to say: > type c = < add : int -> 'a; .. > as 'a Impossible in ocaml 3.08.3. With ocaml 3.09 (CVS version) type c = private < add : int -> 'a; .. > as 'a is exactly what you are asking for. And before someone asks, you of course cannot inherit from such a generic class (even if it were declared as a class rather than an object type), as there is no way to know what other public methods it could (i.e. they might be incompatible to the ones you add inside your functor.) Jacques