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 SAA29846; Thu, 12 Jun 2003 18:35: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 SAA29824 for ; Thu, 12 Jun 2003 18:35:44 +0200 (MET DST) Received: from mail.speakeasy.net (mail13.speakeasy.net [216.254.0.213]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h5CGZhH11688 for ; Thu, 12 Jun 2003 18:35:43 +0200 (MET DST) Received: (qmail 17147 invoked from network); 12 Jun 2003 16:35:41 -0000 Received: from unknown (HELO grace.speakeasy.org) ([216.254.0.2]) (envelope-sender ) by mail13.speakeasy.net (qmail-ldap-1.03) with DES-CBC3-SHA encrypted SMTP for ; 12 Jun 2003 16:35:41 -0000 Date: Thu, 12 Jun 2003 09:35:41 -0700 (PDT) From: brogoff@speakeasy.net To: Mirko Aigner cc: "caml-list@inria.fr" Subject: Re: [Caml-list] dynamic dispatching In-Reply-To: <3EE5AE46.4050307@alcatel.de> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam: no; 0.00; brogoff:01 caml-list:01 dispatching:01 runtime:01 instanceof:01 recursion:01 fixpoint:01 wwwfun:01 ears:99 website's:99 ocaml:01 typechecking:01 speakeasy:01 variants:01 overloading:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tue, 10 Jun 2003, Mirko Aigner wrote: > Hi !! > > I'm new to OCAML and have the following question: > > I have to reimplement some code written in C++. > In C++ there is used a desgin pattern named Visitor, which i used > instead of a dynamic_cast. > My question: is it generally possible to decide at runtime, if an object > is of a specific type ?! The simplest answer to this question is, "no". There is no Java style instanceof in the language. If this is something you do frequently, you would instead use sum types instead of classes. If you insist on using classes, you can program the visitor pattern easily in OCaml. Even though there is no method overloading, there are plenty of other features which make up for it. If you decide to use sum types, you may be troubled by inability to extend the sum type without rewriting code. By using polymorphic variants, and hand coding the open recursion using a fixpoint function, you can get around these problems. The basic idea is here http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/papers/fose2000.html but be warned; if you're an FPL beginner this will make your eyes bleed and your brains drip out your ears. I suggest that you try to solve the problem in the core language (no OO or polymorphic variants) + modules before anything else. > What I have read in the reference manual and some website's dynamic > typechecking is not supported, means this dynamic dispatching as well ?! > > I'm grateful for any answers ( positive or negative ) Good programming language choice, welcome aboard. -- Brian ------------------- 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