From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA08690; Mon, 14 Jun 2004 17:50:52 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 RAA05809 for ; Mon, 14 Jun 2004 17:50:50 +0200 (MET DST) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i5EFolSH018337 for ; Mon, 14 Jun 2004 17:50:48 +0200 Received: from [192.168.1.200] (ppp219-112.lns2.syd3.internode.on.net [203.122.219.112]) by smtp1.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id i5EFnM4Y035818; Tue, 15 Jun 2004 01:19:23 +0930 (CST) Subject: Re: [Caml-list] troubles with polymorphic variant in class From: skaller Reply-To: skaller@users.sourceforge.net To: IdeFX@Iname.com Cc: caml-list In-Reply-To: <1087205340.8886.4.camel@Bess> References: <1087142756.10383.50.camel@Bess> <1087149590.16811.1342.camel@pelican.wigram> <1087205340.8886.4.camel@Bess> Content-Type: text/plain; charset=UTF-8 Message-Id: <1087228160.16811.1370.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 15 Jun 2004 01:49:21 +1000 Content-Transfer-Encoding: 8bit X-Miltered: at concorde with ID 40CDC957.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 sourceforge:01 2004:99 val:01 childs:01 childs:01 widget:01 unifying:01 widget:01 abstraction:01 gui:01 widgets:01 9660:01 glebe:01 unify:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, 2004-06-14 at 19:29, François-Xavier HOUARD wrote: > But the answer you gave me, which I find quite nice, don't allow my user > to add his own class.... They would have to edit the module to do it, but they can do it. Here is another solution: visitor pattern. class 'w window = object (self) val mutable childs: 'w list ... method iter (f:'w -> unit) = List.iter f childs end ... user now can write: type 'w mywidgets' = [`A of 'w a_kind' | `B of 'w b_kind' .. ] class ['w] a_kind' = object ..... class a_kind = widget a_kind' ... etc etc as before. Now the *user* must unify all the types with a variant, but the class doesn't need to know what is is until it is instantiated. One way or the other there is no alternative to unifying all the widget types with a sum (variant) or an abstraction (class supertypes) or both. Typical GUI like GTK do both (there are run time tests for kinds of widgets, so you can do button specific things on any kind of button etc). -- John Skaller, mailto:skaller@users.sf.net voice: 061-2-9660-0850, snail: PO BOX 401 Glebe NSW 2037 Australia Checkout the Felix programming language http://felix.sf.net ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners