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 29, 2006, at 5:03 AM, Gerd Stolpmann wrote:

> Certainly not this way. Simply use exceptions for home-made RTTI:
>
> class type foo = ...
>
> exception Foo of foo
>
> class foo_class : foo =
> object(self)
>    ...
>    method downcast = raise(Foo(self : #foo :> foo))
> end
>
>
> let downcast_foo (obj : < downcast : unit; ..>) =
>   try obj # downcast
>   with Foo x -> x
>      | _ -> failwith "This is not a foo!"
>
>
> Although this is restricted to monomorphic types please note that the
> other languages you mention only have this sort of types.

This is a cute idea.  I'm glad that you mentioned the point about  
monomorphic types.  Hypothetically, is there any need for  
"polymorphic" downcasts?