Re: down casting ???

Didier Remy (Didier.Remy@inria.fr)
Thu, 20 Jun 1996 19:05:49 +0200 (MET DST)

Message-Id: <199606201705.TAA03263@pauillac.inria.fr>
Subject: Re: down casting ???
To: Jean-Marie.Favre@imag.fr (FAVRE Jean-Marie)
Date: Thu, 20 Jun 1996 19:05:49 +0200 (MET DST)
In-Reply-To: <9606190903.ZM4853@tassili> from "FAVRE Jean-Marie" at Jun 19, 96 09:03:01 am
From: Didier.Remy@inria.fr (Didier Remy)

> 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
typecase.

> 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.

Didier.