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 QAA10975; Thu, 26 Sep 2002 16:32:21 +0200 (MET DST) 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 QAA10978 for ; Thu, 26 Sep 2002 16:32:20 +0200 (MET DST) Received: from iona.labri.fr (iona.labri.fr [147.210.8.143]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g8QEWJD22547 for ; Thu, 26 Sep 2002 16:32:19 +0200 (MET DST) Received: from localhost (localhost.localdomain [127.0.0.1]) by iona.labri.fr (Postfix) with ESMTP id DC13C7DA1 for ; Thu, 26 Sep 2002 16:32:15 +0200 (CEST) Received: from serveur4.labri.fr (serveur4.labri.fr [147.210.8.81]) by iona.labri.fr (Postfix) with ESMTP id F3D187D97 for ; Thu, 26 Sep 2002 16:32:14 +0200 (CEST) Received: (from vanicat@localhost) by serveur4.labri.fr (8.11.6/8.11.6) id g8QEWIu07987; Thu, 26 Sep 2002 16:32:18 +0200 X-Authentication-Warning: serveur4.labri.fr: vanicat set sender to vanicat@labri.u-bordeaux.fr using -f To: caml-list@inria.fr Subject: Re: [Caml-list] a design problem requiring downcasting? (long) References: <200209260901.g8Q910t03459@orchestra.cs.caltech.edu> From: Remi VANICAT In-Reply-To: <200209260901.g8Q910t03459@orchestra.cs.caltech.edu> Date: 26 Sep 2002 16:32:18 +0200 Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by AMaViS new-20020517 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Michael Vanier writes: [...] > These method calls are highly dependent on the > specific types of the objects. If you create the objects like this: > > let obj1 = new class1 in > let obj2 = new class2 in > obj1#my_method obj2 > > then everything works. However, it is not feasible, when writing a > simulation with this many objects, to keep unique identifiers to each object > that you create. Therefore, you need some kind of data structure to store > objects after you create them. For our purposes we can assume that there is > a big master array of these objects. I see two alternatives for the types of > the array elements. > > 1) All elements will be instances of subclasses of a base type "base". The > array will have the type "base array". > > 2) The array will be of type "anObject array", where anObject is a variant type > that can hold the type of any simulation object. > > With alternative (1), to do the method call above you would need downcasting > e.g. in pseudo-ocaml: > > let obj1 = array.(0) as class1 in > let obj2 = array.(1) as class2 in > obj1#my_method obj2 > Well, my problem when I read this is the foolowing : How do you know that you have to call the method my_method of the #2341 object with the #5232 as argument ? This information is somewhere (It can't come from nowhere) so There the type information could be stored (I mean, may be you could put there not the position of the object in the array, but the object itself). Otherwise there is severall way to make downcast in caml : you could look to coca-ml (http://www.pps.jussieu.fr/~emmanuel/Public/Dev/coca-ml/index-en.html) or to the hweak library (http://aspellfr.free.fr/) -- Rémi Vanicat vanicat@labri.u-bordeaux.fr http://dept-info.labri.u-bordeaux.fr/~vanicat ------------------- 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