Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Re: down casting ???
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1996-06-20 (17:11)
From: Didier.Remy@i...
Subject: Re: down casting ???

> the :> operator make possible to coerce an expression from a type t1 to a
> super type t (this coercion is safe), but how to go from t to t1 ???
> (ok, a dynamic check is need, this operation can raise an exception)

Yes, the coercion is unsafe and a dynamic check is needed.  As you mention,
this could be implemented with dynamics (values carrying their types) and a

> When one use collections of object, this kind of feature is useful. 

Yes, this is a typical  example where such a construction would be
convenient. The  way to solve it now is to declare a data type with one
constructor for each different kind of objet that you want to retreive
from the collection (as you would do in ML without objects). 

> (a kind of typecase construction as it is the case in modula 3).
> is it possible ???

Yes, it is. However, dynamics and typecase complicate the language, its
semantics, and its implementation; so, we preferred not to include them.