From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id GAA20704; Fri, 21 Dec 2001 06:07:35 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id GAA20635 for ; Fri, 21 Dec 2001 06:07:34 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id fBL57WP05353 for ; Fri, 21 Dec 2001 06:07:33 +0100 (MET) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id OAA17070; Fri, 21 Dec 2001 14:06:58 +0900 (JST) To: patrick@watson.org Cc: caml-list@inria.fr Subject: Re: [Caml-list] Objects and private methods In-Reply-To: <20011220215627.C91723-100000@fledge.watson.org> References: <20011220215627.C91723-100000@fledge.watson.org> X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20011221140658Z.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 21 Dec 2001 14:06:58 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > I'm having some trouble getting the following type of structure to > type-check: > > class type a = object method get_b : a end > > and b = object method b : unit end > > class a_impl = > (object (self) > method get_b = (self :> b) > method private b = () > end : a) > ;; > > This produces the error message: > > The class type object method b : unit method get_b : b end > is not matched by the class type a > The public method b cannot be hidden > > I would have expected the failure to occur when coercing to type 'b' as > the method is declared private (which does not match the signature). Due to the way privacy attributes are implemented in the type checker, a type annotation can force a private method to become public (but never the opposite). You can see it on the following example. # class c = object (self : < b : 'a; .. >) method private b = 1 end;; class c : object method b : int end This explains why the type checker doesn't complain about b not being public: it makes it public as needed. And since b is public, you cannot hide it. (This may seem strange from the point of view of privacy, but you should just understand private methods as "may be hidden in a subclass"; if unified with a public method it may no longe be hidden.) > The basic idea is that the class 'a_impl' implements 'b' privately. This > seems like something that should be possible to do. I suspect that the > coercion of self to 'b' is causing the problem here. I don't understand very well what you mean by "implement privately": a and b do not seem to be related in your code. I will suppose that you meant class type a = object method get_b : b end You cannot convert something from private to public through a coercion (this is different from forcing it with an annotation). This is because the values are actually different: a private method and a public method have different internal representations. On the other hand, you can hide a method through coercions. class a_impl = object (self) method get_b = (self :> b) method b = () end let new_a = (new a_impl :> a) --------------------------------------------------------------------------- Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp JG ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr