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 SAA09898; Sun, 13 Jun 2004 18:06:00 +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 SAA10606 for ; Sun, 13 Jun 2004 18:05:59 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from postfix3-2.free.fr (postfix3-2.free.fr [213.228.0.169]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i5DG5wSH008093 for ; Sun, 13 Jun 2004 18:05:58 +0200 Received: from [192.168.2.8] (auteuil-1-81-57-2-20.fbx.proxad.net [81.57.2.20]) by postfix3-2.free.fr (Postfix) with ESMTP id 802ACC59C for ; Sun, 13 Jun 2004 18:05:57 +0200 (CEST) Subject: [Caml-list] troubles with polymorphic variant in class From: =?ISO-8859-1?Q?Fran=E7ois-Xavier?= HOUARD Reply-To: IdeFX@Iname.com To: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-15 Message-Id: <1087142756.10383.50.camel@Bess> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 Date: Sun, 13 Jun 2004 18:05:57 +0200 Content-Transfer-Encoding: 8bit X-Miltered: at concorde with ID 40CC7B66.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; iname:99 gui:01 gui:01 widget:01 widget:01 val:01 val:01 childs:01 childs:01 foo:01 foobar:01 foobar:01 coca-ml:01 enfants:99 pere:99 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk English version: Hi everyone I'm working on an ocaml GUI library -more information about it later, on the list ;) I'm now working on an introspecting side of this GUI library; in a GUI, every composant can have some child, and have a father. The choice I'v made is to have a class for every type of composant, and an object for every composant, for example, I have a window class, a frame class (inheriting window), a button class, a panel class, etc. So, as every composant can have different type of father, every object is parametrized by the type of his father, for example, a button in a panel in a window is, for the moment, typed as window panel button as the button class looks like that: class ['a] button (father:'a) .... and the panel too,etc I find it nice, cause every widget has got his "genealogic tree" in his type. What I wan't now is to store every widget child in a list. as every child should be from a different type, and as I wan't the user to be able to add his own widget-class later, I first thought of the use of polymorphic variant, like that: class ['a] button (father:'a) = object(self) val f = father val mutable childs = [`Whatever] method add_child (x) = childs <- x::childs method get_variant = `A self end;; but caml tells me that: The method add_child has type ([> `Whatever ] as 'a) -> unit where 'a is unbound This could be solved by adding a 'b parameter to my class: class ['a, 'b] button (father:'a) = object(self) val f = father val mutable childs = [`Whatever] method add_child (x:'b) = childs <- x::childs method get_variant :'b = `A self end;; but this may make my class type unreadable: [> 'Whatever | `Window of window ] window [> 'Whatever | `Window of window | `Panel of panel ] panel [> 'Whatever | `Window of window | `Panel of panel | `Button of button ] button So, I have 2 questions: _ Why should an open type as [>`Whatever] be parameter of a class ?? As far as I know it, [>`Whatever] is equivalent to [>`Whatever | `Foo of bar | `Foobar of foobar ], isn't it ?? so what problem would it make for the inheritage stuff (which are the reason of the use of parameter) _Is there another way to make it ??? (yes, i know coca-ml, but, another way ??) Thanks for all FX Houard Version Française: Bonjour tous le monde je travail sur une librairie de GUI en Caml -plus d'infos plus tard sur la liste ;) Je travail sur la partie introspective de cette librairie de GUI; dans une GUI, chaque composant peut avoir des enfants, et a un père. Le choix que j'ai fais est d'avoir une class pour chaque type de composant, et un objet pour chaque composant; par exemple, j'ai une class de "fenetre", in class de "frame", une de panel, une de bouton, etc... Donc, comme chaque composant peut avoir un père de type différent, chaque objet est paramétré par le type de son père, par exeample, un bouton dans un panel dans une fenetre a le type: window panel button comme la classe bouton ressemble à ça: class ['a] button (father:'a) .... et la classe panel aussi, etc.. je trouve ça plutôt chouette, puisque chaque widget a son arbre généalogique dans son type Ce que je voudrais maintenant, c'est stocker les enfants de chaque widget dans une liste. Comme chaque enfant peut être d'un type différent, et comme je veux que l'utilisateur puisse rajouter ses propres classes de widget, j'ai d'abord pensé aux variants polymorphes: class ['a] button (father:'a) = object(self) val f = father val mutable childs = [`Whatever] method add_child (x) = childs <- x::childs method get_variant = `A self end;; Mais caml me réponds The method add_child has type ([> `Whatever ] as 'a) -> unit where 'a is unbound (je vais pas traduire ça, non plus !!;) Celà pourrait être résolu en ajoutant le paramètre 'b à ma classe: class ['a, 'b] button (father:'a) = object(self) val f = father val mutable childs = [`Whatever] method add_child (x:'b) = childs <- x::childs method get_variant :'b = `A self end;; Mais ça devrait rendre mes types illisibles: [> 'Whatever | `Window of window ] window [> 'Whatever | `Window of window | `Panel of panel ] panel [> 'Whatever | `Window of window | `Panel of panel | `Button of button ] button J'ai donc 2 questions: _Pourquoi un type ouvert comme [>`Whatever] devrait être un paramètre de ma classe ? d'autant que je le sache, [>`Whatever] est équivalent à [>`Whatever | `Foo of bar | `Foobar of foobar ], non ?? Alors quel problème pour l'héritage (qui est la raison de l'utilisation de paramètre) celà ferait il ?? _Y aurait il une autre façon de faire ce que je veux (je connais certe coca-ml, mais, une autre façon existe peut être) ? Merci pour tous FX Houard ------------------- 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