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=1.1 required=5.0 tests=AWL,SPF_FAIL autolearn=disabled version=3.1.3 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id AB97EBBCA for ; Tue, 26 Feb 2008 16:37:59 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAGPBw0fVpUAUmWdsb2JhbACQYwEBAQEBBgQGCQgWnCs X-IronPort-AV: E=Sophos;i="4.25,407,1199660400"; d="scan'208";a="8611394" Received: from mail.gmx.net ([213.165.64.20]) by mail1-smtp-roc.national.inria.fr with SMTP; 26 Feb 2008 16:37:59 +0100 Received: (qmail invoked by alias); 26 Feb 2008 15:37:58 -0000 Received: from dialin-145-254-250-137.pools.arcor-ip.net (EHLO dialin-145-254-250-137.pools.arcor-ip.net) [145.254.250.137] by mail.gmx.net (mp001) with SMTP; 26 Feb 2008 16:37:58 +0100 X-Authenticated: #11134691 X-Provags-ID: V01U2FsdGVkX1+wITAmreawDXViK3tgtESMwa58o/7xUiIKkEurog AC5YFxh2YQmWxZ Received: from dirk by feanor.private-host.de with local (masqmail 0.2.20) id 1JU1Oh-1hQ-00 for ; Tue, 26 Feb 2008 16:07:11 +0100 Date: Tue, 26 Feb 2008 16:07:11 +0100 To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Objects, dynamic cast, Obj.magic abuse and dragons Message-ID: <20080226150711.GB6521@feanor> References: <47C3F96E.4080901@exalead.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <47C3F96E.4080901@exalead.com> User-Agent: Mutt/1.5.6+20040523i From: Dirk Thierbach X-Y-GMX-Trusted: 0 X-Spam: no; 0.00; 0100,:01 berke:01 durak:01 pointer:01 model:01 variants:01 nodes:01 26,:98 hero:98 wrote:01 caml-list:01 inherit:01 behaviour:01 tree:02 tree:02 On Tue, Feb 26, 2008 at 12:35:10PM +0100, Berke Durak wrote: > In this adventure, things can contain other things; a class physical has a > list of things it contains, and an optional pointer to its container. > > Persons, places and objects are things so they inherit from physical. > Hence, a forest is a place that can contain > a sword (an object), a dragon (a person) or another place (a small house). > Persons can be contained in places > or things (coffins). > > 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 think I wouldn't use objects at all in this situation. You're trying to model the location-tree of "physical" things. A tree must be uniform in its contents, but you want to put different things into it. That means you must use an algebraic type, or variants. I'd probably either use a zipper, or connect the tree nodes with "refs" for the non-pure version. Attaching operations like "go" to a specific object is also a leftover from the "everything is an object" philosophy. If you must move a physical thing, just move it. If you need to attach special behaviour for some sort of movements, find out what it depends on (source, destination, thing moved, or a combination) and handle those cases in the move-routine. - Dirk