English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] dynamic runtime cast in Ocaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-11-07 (07:08)
From: Michael Vanier <mvanier@c...>
Subject: Re: [Caml-list] dynamic runtime cast in Ocaml

> Date: Wed, 6 Nov 2002 13:54:28 +0100
> From: Xavier Leroy <xavier.leroy@inria.fr>
> > 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

I started that thread, and I concluded at the end of it that all approaches
to simulating downcasting in ocaml were, at best, hacks.  From there it was
a short step to concluding that ocaml was simply not the best choice for my
application.  This is not to disparage ocaml, which is still my favorite
computer language, but sometimes you need something more dynamic.  Dynamic
is not a dirty word ;-)

I understand some of the objections to downcasting, but what I'm really
curious about is this: if the ocaml team really *wanted* to allow downcasts
(raising an exception on failure just like dividing by zero does), would it
be technically feasible?  By feasible I mean doable without nasty Obj.magic
hacks (no offense to coca-ml, which is very clever).

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