From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 848B1BB81 for ; Sat, 18 Dec 2004 05:00:35 +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 iBI40Ze4032575 for ; Sat, 18 Dec 2004 05:00:35 +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 FAA25754 for ; Sat, 18 Dec 2004 05:00:34 +0100 (MET) Received: from swordfish.havenrock.com ([216.241.35.41]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id iBI40Xt4032572 for ; Sat, 18 Dec 2004 05:00:34 +0100 Received: from [127.0.0.1] (swordfish [127.0.0.1]) by swordfish.havenrock.com (Postfix) with ESMTP id 9909CCFCC for ; Fri, 17 Dec 2004 21:00:53 -0700 (MST) Message-ID: <41C3AB71.4070107@havenrock.com> Date: Fri, 17 Dec 2004 21:00:49 -0700 From: Matt Gushee User-Agent: Mozilla Thunderbird 0.8 (X11/20040916) X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] Type problem... possible design problem References: <41C37CF7.5050400@ntlworld.com> In-Reply-To: <41C37CF7.5050400@ntlworld.com> X-Enigmail-Version: 0.86.1.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 41C3AB63.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 41C3AB61.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 wrote:01 childnode:01 o'caml:01 childnode:01 ...:98 ....:98 ...:98 signatures:01 define:01 coerce:01 unit:02 unit:02 objects: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: chris.danx wrote: > type childNode = LeafNode of sgLeaf | IntNode of sgInternal > and > class sgLeaf .... etc. ... > 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? This seems to me like a good case for class types. How about something like: class type leafType = object method draw : unit -> unit end class type ['a] internalType = object method addChild : 'a -> unit method getChildren : unit -> 'a list method draw : unit -> unit end type childNode = LeafNode of leafType | IntNode of childNode internalType Then, of course, you'll need to define concrete classes that fit the class type signatures and/or coerce objects to those types. I'm not sure this is the most elegant solution, but it is at least syntactically valid, and seems to do what you want. -- Matt Gushee Englewood, CO, USA