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 EAA03236; Thu, 7 Nov 2002 04:30:05 +0100 (MET) 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 EAA02137 for ; Thu, 7 Nov 2002 04:30:04 +0100 (MET) Received: from cs.rice.edu (cs.rice.edu [128.42.1.30]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id gA73U3D05226 for ; Thu, 7 Nov 2002 04:30:03 +0100 (MET) Received: from localhost (localhost [127.0.0.1]) by cs.rice.edu (Postfix) with SMTP id ED4C34AAB5 for ; Wed, 6 Nov 2002 21:29:35 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by cs.rice.edu (Postfix) with ESMTP id B8E964AA5D for ; Wed, 6 Nov 2002 21:29:35 -0600 (CST) Received: from frosty.cs.rice.edu (frosty.cs.rice.edu [128.42.1.20]) by cs.rice.edu (Postfix) with ESMTP id 63BA14AA26 for ; Wed, 6 Nov 2002 21:29:33 -0600 (CST) Received: from localhost (taha@localhost) by frosty.cs.rice.edu (8.9.3+Sun/8.9.0) with ESMTP id VAA07171 for ; Wed, 6 Nov 2002 21:29:00 -0600 (CST) X-Authentication-Warning: frosty.cs.rice.edu: taha owned process doing -bs Date: Wed, 6 Nov 2002 21:28:59 -0600 (CST) From: Walid Taha Cc: Subject: Re: [Caml-list] dynamic runtime cast in Ocaml In-Reply-To: <20021106135428.A8640@pauillac.inria.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS snapshot-20020300 X-DCC--Metrics: cs.rice.edu 1067; Body=1 Fuz1=1 Fuz2=1 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Were nested quantifiers (either existentials or universals) considered in the context of OCaml? If not, are there plans to add them? Thanks. Walid. On Wed, 6 Nov 2002, Xavier Leroy wrote: |> 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? | |There was a long thread on this topic on this list not long ago. |Several approaches were discussed: using datatypes (Point of point | |CPoint of cpoint), extensible datatypes (via the type "exn" of |exceptions), etc. See also Coca-ML: |http://www.pps.jussieu.fr/~emmanuel/Public/Dev/coca-ml/index-en.html | |This said, my opinion on downcasts is that they are a low-level, |dangerous feature that is best replaced by advanced, statically-typed |constructs like OCaml provides. (Some day, I'll have a bumper sticker |custom-made that reads "Caml programmers do it statically".) | |In my (admittedly limited) experience with Java, 95% of downcasts in |Java code fall in one of the following scenarios: |- when using container classes (program puts a Foo in a Hashtable, | reads it back as Object, needs downcast to Foo); |- when using binary methods (equal(), compare()) |- to encode sum types (a Foo is a Bar or a Gee). | |The OCaml type system is able to type-check all three scenarios |statically, using parameterized classes, "mytype" specialization, |and datatypes / variants (respectively). | |The remaining 5% of downcasts were kludges where the programmer |managed to ruin a perfectly good class hierarchy by sprinkling type |tests everywhere, rather than subclassing and redefining virtual |methods adequately in classic OO fashion. | |To be fair, I may have missed some legitimate uses of downcasts in |complicated situations. But I believe these legitimate uses are |uncommon enough that it is best to find another way to express the |desired behavior, rather than extend OCaml with downcasts. | |That you can do self-modifying code in assembler, Duff's device in C, |or downcasts in Java doesn't mean that you want to do it in OCaml as |well :-) | |- Xavier Leroy |------------------- |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 | ------------------- 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