From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA01549 for caml-redistribution; Thu, 21 Nov 1996 16:58:31 +0100 (MET) 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 PAA28662 for ; Thu, 21 Nov 1996 15:22:30 +0100 (MET) Received: from margaux.inria.fr (margaux.inria.fr [128.93.8.2]) by concorde.inria.fr (8.7.6/8.7.1) with ESMTP id OAA28054 for ; Thu, 21 Nov 1996 14:56:05 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by margaux.inria.fr (8.7.6/8.7.3) with ESMTP id OAA26926 for ; Thu, 21 Nov 1996 14:55:56 +0100 (MET) Received: from irz301.inf.tu-dresden.de (irz301.inf.tu-dresden.de [141.76.1.11]) by concorde.inria.fr (8.7.6/8.7.1) with SMTP id OAA28041 for ; Thu, 21 Nov 1996 14:55:40 +0100 (MET) Received: from tcs.inf.tu-dresden.de (tcs.inf.tu-dresden.de [141.76.75.101]) by irz301.inf.tu-dresden.de (8.6.12/8.6.12-s1) with SMTP id OAA03635 for ; Thu, 21 Nov 1996 14:55:09 +0100 Received: from ithif18.inf.tu-dresden.de by tcs.inf.tu-dresden.de (4.1/SMI-4.1) id AA06922; Thu, 21 Nov 96 14:55:08 +0100 Received: by ithif18.inf.tu-dresden.de (SMI-8.6/SMI-SVR4) id OAA10366; Thu, 21 Nov 1996 14:57:42 +0100 Date: Thu, 21 Nov 1996 14:57:42 +0100 Message-Id: <199611211357.OAA10366@ithif18.inf.tu-dresden.de> From: Hendrik Tews To: caml-list@margaux.inria.fr Subject: Questions about class types Sender: weis Hello, I want to write a module which provides a class with some features, say #module type A = sig # class b (unit)= method init : unit # end #end;; but I want to implement it via a class with more features, say #module B = struct # class b () as self = # val a = () # method init = self#f # method f = a # end #end;; Unfortunately B does not match A, because (as it is written in the documentation under 4.9.2) one can add additional instance variables, but no additional methods. What is the reason for this? As you can guess I would like additional methods to get hidden when matching a class against a class type. The first idea is to implement f as an instance variable (of functional type) as well, but this gets very ugly as soon as there are some mutually recursive f's. The next idea was to specify only a type and some functionality, not a class ie: #module type A' = sig # val newb : unit -> < init : unit; .. > #end;; # #module B' : A' = struct # class b () as self = # val a = () # method init = self#f # method f = a # end # # let newb () = new b () #end;; The disadvantage of this approach would be that a user of A' can't use new, because he does not have access to the class. To my surprise it did not type check, because Values do not match: val newb : unit -> b is not included in val newb : unit -> < init : unit; .. > Even with explicit typing newb, ie substituting # let newb () : < init : unit; .. > = ((new b ()) : < init : unit; .. >) I get the same error. So far I thought, that a class type is only a abbreviation for something like < .. >. Where am I wrong? Bye, Hendrik Tews ------------------------------------------------------------- e-mail: tews@tcs.inf.tu-dresden.de www: http://www.inf.tu-dresden.de/~ht1 Console: ithif18.inf.tu-dresden.de