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 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 5C7A8BBCA for ; Wed, 27 Feb 2008 10:30:09 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAN68xEfVpUAUmWdsb2JhbACQZwEBAQEBBgQGCQgWgQ+bMA X-IronPort-AV: E=Sophos;i="4.25,412,1199660400"; d="scan'208";a="9641737" Received: from mail.gmx.net ([213.165.64.20]) by mail3-smtp-sop.national.inria.fr with SMTP; 27 Feb 2008 10:30:09 +0100 Received: (qmail invoked by alias); 27 Feb 2008 09:30:06 -0000 Received: from dialin-145-254-247-017.pools.arcor-ip.net (EHLO dialin-145-254-247-017.pools.arcor-ip.net) [145.254.247.17] by mail.gmx.net (mp001) with SMTP; 27 Feb 2008 10:30:06 +0100 X-Authenticated: #11134691 X-Provags-ID: V01U2FsdGVkX18ToewQlXATeQKn90YQruKPWoert3JSUMS81OtuHt BP2RS5wrC1iSPu Received: from dirk by feanor.private-host.de with local (masqmail 0.2.20) id 1JUGr0-0vx-00 for ; Wed, 27 Feb 2008 08:37:26 +0100 Date: Wed, 27 Feb 2008 08:37:26 +0100 To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Objects, dynamic cast, Obj.magic abuse and dragons Message-ID: <20080227073726.GA1494@feanor> References: <47C3F96E.4080901@exalead.com> <20080226150711.GB6521@feanor> <47C43D61.7070905@exalead.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <47C43D61.7070905@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 model:01 variants:01 nodes:01 gerd:01 stolpmann:01 bug:01 guis:01 subtyping:01 partitioned:01 uniformly:01 statically:01 ocaml:01 On Tue, Feb 26, 2008 at 05:25:05PM +0100, Berke Durak wrote: > Dirk Thierbach wrote : >> 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. > You are preaching to the choir. I'm not preaching here :-) > I'm not Gerd Stolpmann and I don't use objects very much because > every time I try I get seven-page-long errors. I, OTOH, use them frequently. I also get seven-page-long errors, but usually I can find the bug nevertheless :-) > However it seems that objects could be actually useful in situations > where you have a hierarchy of objects with behaviours, such as a graphical > user interface made of widgets, or, say, a text adventure. Yes, they can be very useful in some situations, especially in GUIs. However, I think they are not useful in the particular situation of a text adventure. And I think that the criterion is not having a hierarchy of behaviours (first, "inheritance is not subtyping", second, as you've seen, you can run into trouble with static type checking easily), but the criterion is having substantial state that should be partitioned and decoupled. This also applies to the text adventure to some degree, but the actual state is much simpler: Must items will have no state at all, or at most a boolean like "open/closed". Their *relationship*, OTOH (i.e. location, attachment) can be described uniformly and globally. Also, for the actual actions, you need multi-dispatch: The outcome of the action depends on the verb and multiple items ("tie rope to railing"). And all this says that single-dispatch statically typed objects, like in OCaml, are a bad match for this situation. - Dirk