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 04808BCAE for ; Mon, 11 Jul 2005 00:10:07 +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 j6AMA66C023273 for ; Mon, 11 Jul 2005 00:10:06 +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 AAA12156 for ; Mon, 11 Jul 2005 00:10:05 +0200 (MET DST) Received: from swip.net (mailfe10.tele2.se [212.247.155.33]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j6AMA5II023268 for ; Mon, 11 Jul 2005 00:10:05 +0200 X-T2-Posting-ID: 2IIuXFmkcTpj3lKEFKW25A== Received: from [83.176.173.198] (HELO poincare) by mailfe10.swip.net (CommuniGate Pro SMTP 4.3.4) with ESMTPS id 211682940; Mon, 11 Jul 2005 00:10:03 +0200 Received: from [127.0.0.1] (helo=localhost ident=trch) by poincare with esmtp (Exim 4.50) id 1Drjwg-0007lF-Lp; Mon, 11 Jul 2005 00:06:43 +0200 Date: Mon, 11 Jul 2005 00:06:42 +0200 (CEST) Message-Id: <20050711.000642.115315345.debian00@tiscali.be> To: angagon@earthlink.net Cc: caml-list@inria.fr Subject: Re: [Caml-list] Object typing From: Christophe TROESTLER In-Reply-To: <42D063EC.3040900@earthlink.net> References: <42D063EC.3040900@earthlink.net> Organization: Universite de Mons-Hainaut (http://math.umh.ac.be/an/) X-Spook: Majic Blowpipe Adriatic Europol AVN Taiwan Verisign condor strategic Bosnia X-Blessing: Om Ah Hum Vajra Guru Pema Siddhi Hum X-Operating-System: GNU/Linux (http://www.linux.org/) X-Mailer-URL: http://www.mew.org/ X-Mailer: Mew version 4.2.51 on Emacs 21.4 / 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 42D19CBE.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 42D19CBD.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 christophe:01 troestler:01 variants:01 bool:01 bool:01 forall:01 parametrize:01 val:01 2005,:98 wrote:01 unbound:01 polymorphic:01 inherit:01 typing:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.6 required=5.0 tests=FORGED_RCVD_HELO, FROM_ENDS_IN_NUMS autolearn=disabled version=3.0.2 X-Spam-Level: On Sat, 09 Jul 2005, "Matthew O'Connor" wrote: > > Here is a version of what I would like to be able to do, but can't or > don't know how. I would like to use polymorphic variants to enable > easier extensibility of the hierarchy. To understand what does not work, try class entity = object method is_a v = (v = `Entity) end You get an error message of which the important part is "The method is_a has type ([> `Entity ] as 'a) -> bool where 'a is unbound". It says that the method [is_a] is of type 'a -> bool with a constraint on 'a. Since you do not want a method of type (forall 'a) 'a -> bool (written "'a. ([> ] as 'a) -> bool" in your error message), you parametrize the class by that type 'a (the rest is in interactive mode): # 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 # class ['a] predator = object inherit ['a] entity as super method is_a (v:'a) = (v = `Predator) || super#is_a v end;; class ['a] predator : object constraint 'a = [> `Entity | `Predator ] method is_a : 'a -> bool end # let ent = new predator;; val ent : _[> `Entity | `Predator ] predator # ent#is_a `Predator;; - : bool = true # ent#is_a `Entity;; - : bool = true # ent#is_a `Chicken;; - : bool = false P.S. Notice the "_" in "_[> `Entity | `Predator ]". It means that the full type is yet to be determined. Close it before the end of your program.