From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 60406BBCA for ; Tue, 26 Feb 2008 15:28:08 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAISww0fAXQImh2dsb2JhbACQYwEBAQgKKZwT X-IronPort-AV: E=Sophos;i="4.25,407,1199660400"; d="scan'208";a="9611324" Received: from discorde.inria.fr ([192.93.2.38]) by mail3-smtp-sop.national.inria.fr with ESMTP; 26 Feb 2008 15:28:07 +0100 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m1QES7Ti031777 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 26 Feb 2008 15:28:07 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAADaxw0fBL1AZkmdsb2JhbACQYwEBAQEHBAYHIpwN X-IronPort-AV: E=Sophos;i="4.25,407,1199660400"; d="scan'208";a="7722877" Received: from gw.exalead.com (HELO exalead.com) ([193.47.80.25]) by mail2-smtp-roc.national.inria.fr with ESMTP; 26 Feb 2008 15:28:07 +0100 Received: from [192.168.204.148] (madpc064.exalead.com [192.168.204.148]) (authenticated bits=0) by exalead.com (8.14.0/8.14.0) with ESMTP id m1QES1G1032715; Tue, 26 Feb 2008 15:28:01 +0100 Message-ID: <47C421F1.8000608@exalead.com> Date: Tue, 26 Feb 2008 15:28:01 +0100 From: Berke Durak User-Agent: Thunderbird 1.5.0.10 (X11/20070221) MIME-Version: 1.0 To: Richard Jones Cc: Caml-list List Subject: Re: [Caml-list] Objects, dynamic cast, Obj.magic abuse and dragons References: <47C3F96E.4080901@exalead.com> <20080226121451.GA20860@annexia.org> In-Reply-To: <20080226121451.GA20860@annexia.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Miltered: at discorde with ID 47C421F7.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; berke:01 durak:01 berke:01 durak:01 0100,:01 lablgtk:01 val:01 hashtbl:01 hashtbl:01 gtk:01 kludge:01 scalable:01 hash:01 26,:98 hero:98 Richard Jones a écrit : > On Tue, Feb 26, 2008 at 12:35:10PM +0100, Berke Durak wrote: >> The problem is that the main game loop gets the current location by taking >> the container of the hero... which is a physical. However, it needs to >> call the place-specific method "go". > > I only briefly read over this, but maybe the thing you want is an > object memo. There's a specialized one in lablgtk called GUtil.memo, > but the basic source for it could be adapted: > > class ['a] memo () = object > constraint 'a = #widget > val tbl = Hashtbl.create 7 > method add (obj : 'a) = > Hashtbl.add tbl obj#get_id obj > method find (obj : widget) = Hashtbl.find tbl obj#get_id > method remove (obj : widget) = Hashtbl.remove tbl obj#get_id > end > > There's an example of using this if you search down for 'memo' on this > page: > > http://www.ocaml-tutorial.org/introduction_to_gtk > > Rich. > Hello, Your solution first seemed like a kludge but, given the alternatives, it appears to be the best solution. It's nicer than having to add type parameters everywhere and it's scalable: just add one memo kind for each category and make sure everyone registers itself on creation. For destruction, we can use weak hash tables. And it's reasonably efficient (after all, we're using objects here.) -- Berke DURAK