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 MAA09728; Wed, 6 Nov 2002 12:53:50 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 MAA09791 for ; Wed, 6 Nov 2002 12:53:49 +0100 (MET) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from kraid.nerim.net (kraid.nerim.net [62.4.16.95]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id gA6BrmD11447 for ; Wed, 6 Nov 2002 12:53:48 +0100 (MET) Received: from hector.lesours (lesours.starynkevitch.net [80.65.224.217]) by kraid.nerim.net (Postfix) with ESMTP id E833E40F98 for ; Wed, 6 Nov 2002 12:43:59 +0100 (CET) Received: from basile by hector.lesours with local (Exim 3.36 #1 (Debian)) id 189Okm-00080r-00 for ; Wed, 06 Nov 2002 12:53:48 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <15817.713.977123.557926@hector.lesours> Date: Wed, 6 Nov 2002 12:53:45 +0100 To: caml-list@inria.fr Subject: [Caml-list] dynamic runtime cast in Ocaml X-Mailer: VM 7.07 under Emacs 21.2.2 From: Basile STARYNKEVITCH Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Dear Ocaml developers I am sometimes lacking the dynamic cast (with a runtime test) in Ocaml. Assuming that I have the usual point and colored_point classes (as in the 3.06 Manual), I want to deal with point array-s and test if the 3rd point is in fact a colored point. Is there some type-theoritical issues here? I thought a few minutes (assuming a single-inheritance world) and found none, but I am not a type theorist and I am (sadly) not working at INRIA. Perhaps parameterized classes and constraints are an issue... But we ordinary people need some explanations about it.. Is there some implementation issues here? There could be some with multiple-inheritance, but I think that dynamic cast could be restricted to a single-inheritance sub-world, and the classical ObjVlisp model offer a quick runtime test for this. BTW, I believe that the existing runtime has most of the features required for such a test. Is there some syntax issues here? I suggest using the pattern matching with a object keyword, so (* test if a point is in fact a colored one *) let point_is_colored (pt: point) = match pt with object colored_point -> true | _ -> false (* get the color of a point, if the point is not colored, fail *) let color_of_point = function (object colored_point) as p -> p#color | _ -> failwith "no color in point" Actually I really think that the essence of object-orientation is runtime dynamic cast (or class disambiguation or the instanceof Java operator, etc....). I never happen to use Ocaml object system without badly needing such a dynamic cast (of course it can be painfully simulated, etc...). Perhaps the question has been asked a billion times, then it might go into a FAQ. regards. -- Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basilestarynkevitchnet alias: basiletunesorg 8, rue de la Faïencerie, 92340 Bourg La Reine, France ------------------- 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