From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 99BF2BB9A for ; Fri, 21 Oct 2005 22:45:02 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j9LKj2XF014976 for ; Fri, 21 Oct 2005 22:45:02 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA31268 for ; Fri, 21 Oct 2005 22:45:01 +0200 (MET DST) Received: from mz3.forethought.net (mzpi5.forethought.net [216.241.36.14]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j9LKixQL014943 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Fri, 21 Oct 2005 22:45:00 +0200 Received: from [216.241.35.41] (helo=[10.0.0.2]) by mz3.forethought.net with esmtp (Exim 4.51) id 1ET3l3-0003US-Pf for caml-list@inria.fr; Fri, 21 Oct 2005 14:44:58 -0600 Message-ID: <4359534A.7080706@gushee.net> Date: Fri, 21 Oct 2005 14:44:58 -0600 From: Matt Gushee User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051002) X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Polymorphic class types? Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 4359534E.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 4359534B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; high-level:01 ocaml:01 labltk:01 labltk:01 bool:01 widget:01 widget:01 subtypes:01 positioning:98 ...:98 ...:98 collapse:98 collapse:98 polymorphic:01 abstract:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Hello, all-- I am trying to design a high-level GUI library in object-oriented OCaml. It will be based on LablTk, but that's not really relevant--right now I'm just trying to work out skeleton classes; the current code doesn't even import LablTk yet. Anyway, the concept I'm trying to implement is a notecard metaphor, where the user will interact with information through a number of cards, which can be iconified, deiconified, moved around, etc[*]. Cards should also be able to display arbitrary data types--in practice I think the data will mostly be key-value structures where the values are mostly strings, but I don't want to limit it to that. So you are probably starting to get a sense of the problem: I need a basic framework of display logic that is independent of the application data, for positioning cards on the canvas, handling events, etc. But I also need to be able to get and set the content of cards in response to GUI events--the content being some arbitrary data structure, as mentioned above. So I have been trying to work with parameterized class type like this: class type ['a] card = object method id : string method place : int -> int -> unit method show : ?expanded:bool -> unit -> unit method hide : unit -> unit method expand : unit -> unit method collapse : int -> int -> unit method content : (string * 'a) list method title : string end class type ['a] cp_canvas = object method base : Widget.canvas Widget.widget method cards : 'a card list method get_card : string -> 'a card method add_card : 'a card -> unit method show : selection -> unit method hide : selection -> unit method expand : selection -> unit method collapse : selection -> unit end But I don't think it's going to work. The sticking point is that there need to be various subtypes of cards, each with appropriate display logic for its content type, yet the canvas needs to be able to manage cards in a generic manner--i.e. it needs to work with the 'card' type--but of course that type doesn't exist, because 'card' takes a parameter, right? I won't go into detail here about the problems I've been having--I suspect the design is wrong, but I have no clear idea of how to do it right. I know my library could use an abstract 'data' type, which could then be implemented in an application as, for example, type data = | I of int | F of float | S of string ... ... but I'd rather not if it can be helped. And I don't care very much if it's object-oriented ... I started this several months ago and put it aside for a while, so I don't remember what exactly I was thinking, but probably the main point of using objects was to make it easy to add new card types. So, I would appreciate suggestions. [*] Am I reinventing HyperCard? Could be ... -- Matt Gushee Englewood, CO, USA