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 16545BCAE for ; Sun, 10 Jul 2005 01:43:18 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j69NhH2R032578 for ; Sun, 10 Jul 2005 01:43:17 +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 BAA30956 for ; Sun, 10 Jul 2005 01:43:17 +0200 (MET DST) Received: from smtpauth07.mail.atl.earthlink.net (smtpauth07.mail.atl.earthlink.net [209.86.89.67]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j69NhGmw023439 for ; Sun, 10 Jul 2005 01:43:16 +0200 Received: from [70.59.206.57] (helo=[192.168.1.101]) by smtpauth07.mail.atl.earthlink.net with asmtp (TLSv1:RC4-MD5:128) (Exim 4.34) id 1DrOyZ-0006qp-9z for caml-list@inria.fr; Sat, 09 Jul 2005 19:43:15 -0400 DomainKey-Signature: a=rsa-sha1; q=dns; c=simple; s=test1; d=earthlink.net; h=Message-ID:Date:From:User-Agent:X-Accept-Language:MIME-Version:To:Subject:X-Enigmail-Version:X-Enigmail-Supports:Content-Type:Content-Transfer-Encoding; b=MbEwR8XIvM7VPh2+P56id0gm4cHXk92MkDEmYZVVpHWUrbpF2ElDcwM9PZS5rrkS; Message-ID: <42D063EC.3040900@earthlink.net> Date: Sat, 09 Jul 2005 17:55:24 -0600 From: "Matthew O'Connor" User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050331) X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Object typing X-Enigmail-Version: 0.90.2.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-ELNK-Trace: c5e7d5cff6dcd352d780f4a490ca69563f9fea00a6dd62bc4f33b5f5d557c5c037ba47b99391dafe350badd9bab72f9c350badd9bab72f9c350badd9bab72f9c X-Originating-IP: 70.59.206.57 X-Miltered: at concorde with ID 42D06115.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 42D06114.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; functors:01 variants:01 bool:01 ocaml:01 bool:01 immune:98 polymorphic:01 inherit:01 typing:01 matched:01 matched:01 hierarchy:01 hierarchy:01 objects:02 types:02 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: Hello all, I'm in the process of writing a cellular agent-based immune system simulator. It uses objects as the agents/entities. I have a hierarchy of different entity types (ie, entity, cell, bacteria, virus, antigen, etc.). I want to be able to determine, at run time, if a given entity is of a given type. My current solution is to use functors to instantiate a weak set for all the types I care about and then have that type's initializer add itself to the set. Then given an object it is simple to determine if it is a member of that set. This solution works, but it seems to be rather slow. I want to speed this process up. 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. (* test.ml *) class type ientity = object method is_a : [> ] -> bool end class entity : ientity = object method is_a v = if v = `Entity then true else false end class predator = object inherit 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 *) (* ocaml test.ml *) File "test.ml", line 7, characters 0-72: The class type object method is_a : [> `Entity ] -> bool end is not matched by the class type ientity The class type object method is_a : [> `Entity ] -> bool end is not matched by the class type object method is_a : [> ] -> bool end The method is_a has type [> `Entity ] -> bool but is expected to have type 'a. ([> ] as 'a) -> bool I'm at a loss as how to proceed. Any other suggestions or ideas or better solutions would be greatly appreciated. Thank you. Matt