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 38714BCAE for ; Sun, 10 Jul 2005 20:26:06 +0200 (CEST) Received: from zamok.crans.org (zamok.crans.org [138.231.136.6]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j6AIQ5Ja023576 for ; Sun, 10 Jul 2005 20:26:06 +0200 Received: from localhost (localhost.crans.org [127.0.0.1]) by zamok.crans.org (Postfix) with ESMTP id 1EEB78A7D for ; Sun, 10 Jul 2005 20:26:06 +0200 (CEST) Received: from zamok.crans.org ([127.0.0.1]) by localhost (zamok [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 03187-04-3 for ; Sun, 10 Jul 2005 20:26:06 +0200 (CEST) Received: from trantor.glondu.net (localhost.crans.org [127.0.0.1]) by zamok.crans.org (Postfix) with ESMTP id B9E908A5E for ; Sun, 10 Jul 2005 20:26:05 +0200 (CEST) From: Stephane Glondu To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Object typing Date: Sun, 10 Jul 2005 11:25:59 -0700 User-Agent: KMail/1.7.1 References: <42D063EC.3040900@earthlink.net> In-Reply-To: <42D063EC.3040900@earthlink.net> Organization: Crans MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200507101126.00725.Stephane.Glondu@crans.org> X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at crans.org X-Miltered: at concorde with ID 42D1683D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 variants:01 ...:98 wrote:01 polymorphic:01 inherit:01 typing:01 hierarchy:01 let:03 suggestions:05 stephane:07 stephane:07 i'm:08 object:09 object:09 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.2 X-Spam-Level: On Saturday 09 July 2005 16:55, 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. > > [...] > > I'm at a loss as how to proceed. Any other suggestions or ideas or > better solutions would be greatly appreciated. Thank you. How about: (* test.ml *) class ['a] entity = object method is_a (v : 'a) = if v = `Entity then true else false end class ['a] predator = object inherit ['a] entity as super method is_a v = if v = `Predator then true else super#is_a v end let ent = new predator;; ent#is_a `Predator;; (* returns true *) ent#is_a `Entity;; (* returns true *) ent#is_a `Chicken;; (* returns false *) Stephane Glondu.