Version française
Home     About     Download     Resources     Contact us    
Browse thread
Class/prototype-based OO
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Ted Kremenek <kremenek@c...>
Subject: Re: [Caml-list] Class/prototype-based OO
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.