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 MAA22569; Fri, 7 Jun 2002 12:12:45 +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 MAA22553 for ; Fri, 7 Jun 2002 12:12:44 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from athlon.baretta.com (r-mi214-6a39.tin.it [62.211.4.39]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g57ACgH10096 for ; Fri, 7 Jun 2002 12:12:43 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id 29E7F273E4; Fri, 7 Jun 2002 12:18:00 +0200 (CEST) Message-ID: <3D008857.2000501@baretta.com> Date: Fri, 07 Jun 2002 12:17:59 +0200 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0rc1) Gecko/20020417 X-Accept-Language: it, en MIME-Version: 1.0 To: Michael Vanier Cc: Ocaml Subject: Re: [Caml-list] coercions from superclass to subclass? References: <200206062215.g56MF5w19818@orchestra.cs.caltech.edu> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Michael Vanier wrote: > I understand that there is no mechanism to coerce from a superclass to a > subclass in ocaml (i.e. the equivalent of C++'s run-time type > identification or java's instanceof operator). Are there any plans to add > such a capability in the future? > > Mike Jacques Garrigue gave the following explanation a week ago. > By the way, here is a simple way to do downcasts, when > really needed. > > # let tbl : (< >, impl) Hashtbl.t = Hashtbl.create 17 > let register obj = Hashtbl.add tbl (obj :> < >) obj > let recover obj = Hashtbl.find tbl (obj :> < >) ;; > val tbl : (< >, impl) Hashtbl.t = > val register : impl -> unit = > val recover : < .. > -> impl = ------------------- 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