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 74865BB81 for ; Sat, 18 Dec 2004 01:42:34 +0100 (CET) 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 iBI0gYYo012040 for ; Sat, 18 Dec 2004 01:42:34 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA20448 for ; Sat, 18 Dec 2004 01:42:33 +0100 (MET) Received: from mta09-winn.mailhost.ntl.com (mailhost.ntl.com [212.250.162.8]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id iBI0gX5r012037 for ; Sat, 18 Dec 2004 01:42:33 +0100 Received: from aamta08-winn.mailhost.ntl.com ([212.250.162.8]) by mta09-winn.mailhost.ntl.com with ESMTP id <20041218004233.QQHZ22154.mta09-winn.mailhost.ntl.com@aamta08-winn.mailhost.ntl.com> for ; Sat, 18 Dec 2004 00:42:33 +0000 Received: from [80.4.70.84] by aamta08-winn.mailhost.ntl.com with ESMTP id <20041218004233.KLQC7419.aamta08-winn.mailhost.ntl.com@[80.4.70.84]> for ; Sat, 18 Dec 2004 00:42:33 +0000 Message-ID: <41C37CF7.5050400@ntlworld.com> Date: Sat, 18 Dec 2004 00:42:31 +0000 From: "chris.danx" User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: "O'Caml Mailing List" Subject: Type problem... possible design problem Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 41C37CFA.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 41C37CF9.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; nodes:01 childnode:01 childnode:01 o'caml:01 o'caml:01 nodes:01 ntlworld:98 ...:98 ...:98 graph:01 leaf:01 unit:02 unit:02 preserve:02 types:02 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: Hi, What is the solution to the following problem? There are two types of object in a scene graph, those that may have children and those may not. A leaf may not have children. For various reasons, I need to preserve the methods of internal nodes (non leaves). I thought about something like this type childNode = LeafNode of sgLeaf | IntNode of sgInternal and class sgLeaf = object(self) method draw () = () end and class sgInternal = object(self) method addChild (child : childNode) = () method getChildren () = ... method draw () = () end but this isn't legal O'Caml. The following also doesn't work. type childNode = LeafNode of unit; ..> | IntNode of unit; addChild: childNode -> unit; ..> I've not programmed in O'Caml for a while and am not yet fully comfortable with ocamls object system anyway, so I may be being silly. Can anyone shed some light on a solution to this? Basically I need to be able to call addChild, etc for internal nodes if they're not leaves so I need to remember whether the type contains only draw or it also contains addChild, etc. It will be clients that call operations like addChild, getChildren, ... Perhaps this is the wrong solution entirely. Thanks, Chris