From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id A7A8FBCAE for ; Mon, 11 Jul 2005 10:22:54 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j6B8Msec010566 for ; Mon, 11 Jul 2005 10:22:54 +0200 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 KAA02704 for ; Mon, 11 Jul 2005 10:22:53 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j6B8Mp9o010559 for ; Mon, 11 Jul 2005 10:22:52 +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 j6B8MjHD008529; Mon, 11 Jul 2005 17:22:45 +0900 (JST) Date: Mon, 11 Jul 2005 17:22:42 +0900 (JST) Message-Id: <20050711.172242.133294018.garrigue@math.nagoya-u.ac.jp> To: remi.vanicat@gmail.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] Object typing From: Jacques Garrigue In-Reply-To: <6b8a9142050711001847d520c8@mail.gmail.com> References: <42D063EC.3040900@earthlink.net> <20050711.000642.115315345.debian00@tiscali.be> <6b8a9142050711001847d520c8@mail.gmail.com> 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 nez-perce with ID 42D22C5E.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 42D22C5B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 bool:01 val:01 bug:01 variance:01 variance:01 omitted:01 variants:01 cvs:01 occurence:01 val:01 bool:01 bug:01 ...:98 typing: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: Remi Vanicat > Notice that one can do better than this : > # class [+'a] entity = > object > method is_a (v:'a) = (v = `Entity) > end;; > class ['a] entity : > object constraint 'a = [> `Entity ] method is_a : 'a -> bool end > # let e = new entity;; > val e : [> `Entity ] entity = > > now we don't have an _ type, and there is no need to close it before > the end of the program. Thank you for finding a serious bug in the variance check! Didn't it strike you as strange that a method parameter could be declared with a covariant type? This goes clearly against the definition. The problem was that the variance check omitted the row-variable in variants, so that if a variant constraint is used on a type parameter, any variance is accepted... After fixing this in CVS for 3.08.4, you get rightfully: In this definition, a type variable has a variance that is not reflected by its occurence in type parameters. or in 3.09 In this definition, expected parameter variances are not satisfied If you really want to make it covariant, you should define is_a out of the class: # class [+'a] entity = object method classes : 'a = [`Entity] end;; class ['a] entity : object constraint 'a = [> `Entity ] list method classes : 'a end # let e = new entity;; val e : [> `Entity ] list entity = # let is_a ob cl = List.mem cl ob#classes;; val is_a : < classes : 'a list; .. > -> 'a -> bool = (And be careful about the above bug before 3.08.4.) Jacques Garrigue P.S. I really think that the variance check is now OK, but if you find strange behaviours in typing, please report them. Particularly when something that shouldn't type is accepted.