From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.5 required=5.0 tests=SPF_SOFTFAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 2F248BC29 for ; Tue, 29 Aug 2006 05:11:11 +0200 (CEST) Received: from smtp-roam.Stanford.EDU (smtp-roam.Stanford.EDU [171.64.10.152]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k7T3B9eg021635 for ; Tue, 29 Aug 2006 05:11:10 +0200 Received: from [192.168.1.10] (rescomp-04-35677.Stanford.EDU [128.12.177.67]) (authenticated bits=0) by smtp-roam.Stanford.EDU (8.12.11/8.12.11) with ESMTP id k7T3B5eJ023463 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT); Mon, 28 Aug 2006 20:11:05 -0700 In-Reply-To: <1156505490.20759.354.camel@rosella.wigram> References: <53c655920608250051x48d81cbagabf8039f0269beee@mail.gmail.com> <1156505490.20759.354.camel@rosella.wigram> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Cc: david.baelde@ens-lyon.org, Ocaml Content-Transfer-Encoding: 7bit From: Ted Kremenek Subject: Re: [Caml-list] Class/prototype-based OO Date: Mon, 28 Aug 2006 20:11:03 -0700 To: skaller X-Mailer: Apple Mail (2.752.2) X-Miltered: at nez-perce with ID 44F3B04D.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; ocaml:01 ocaml:01 lacks:01 downcasts:01 run-time:01 rtti:01 run-time:01 downcasts:01 rtti:01 2006,:98 wrote:01 typing:01 typing:01 signatures:01 signatures:01 On Aug 25, 2006, at 4:31 AM, skaller wrote: > Thus, from a software engineering viewpoint, nominal typing > is not a viable option .. which is one reason programming > in Java or C++ using OO sucks. > > In Ocaml, it works much better because you can actually > write algorithms which work with many different types, > provided only they support the 'right methods'. While the structural typing in Ocaml is wonderful (I really love it), there are missing features of the OO system in OCaml that can be particularly bothersome, and are worth considering when comparing the OO features of Ocaml with other languages (including those that use nominal typing). For example, from what I can tell it appears that Ocaml lacks real support for "downcasts" in the language, which require run-time type information (RTTI) and run-time checks. In the context of structural typing, I am talking about "casting" an object with a type with a given set of method signatures to another type with an extended set of method signatures. Whether or not you agree downcasts are a good thing, it is one thing to take into account when comparing the OO features of different languages (and this is a feature that both C++ and Java have that OCaml does not). In general, I don't believe the OO system in Ocaml supports any kind of RTTI, which enables features such as downcasts and reflection. All of the type checking of objects in OCaml is static, which is very nice but often insufficient. Actually, if I am wrong about this I would be very happy if someone out there can point this out. Certainly one can implement downcasts using Obj.magic and some hand-crafted RTTI, but that is obviously not a desired solution.