On 27-Sep-1999, Alex Ferguson <[EMAIL PROTECTED]> wrote:
> 
> Kevin Atkinson, replying to me:
> 
> > > If I understand you correctly, then the best way of doing this would be
> > > with existentially (boundedly) quantified data types, currently a
> > > non-standard extention present in hbc (and I think, ghc, these days, not
> > > sure if it's with the same generality.)
> > 
> > existentially (boundedly) quantified data types can not cast up.
> 
> 'Cast up' to what?  If you can't write a class context that descibes
> the relatedness of everything you want to put in a heterogenous collection,
> then I'm inclined to doubt if it isn't more heterogenous than is
> sensible.
...
> I don't see how this relates to anything other than heterogenous collections;
> perhaps an example?

One example is the case where you already have existing code that
creates a heterogenous collection, and you want to extract an
element from that heterogenous collection, and then if it is
a member of a particular type class perform action A otherwise
perform action B, *without* modifying the existing code.

The same issue comes up if you have an existing interface
that invokes a callback function with a polymorphic type,
and you want some particular instance of this callback function
to examine the polymorphically typed value that it was given
and to perform action A if it is a member of a particular
type class and action B otherwise.

Typically action A will be some action that makes use of the methods
in the type class, and action B will be a fall-back algorithm.

> > In order to do that you would ALSO need to use the dramatic typing
> > extensions found in the GHC/Hugs library.

I think you mean the _dynamic_ typing extensions ;-)

The dynamic typing extensions in GHC/Hugs will let you cast to a particular
type, but they won't let you check whether that a dynamically typed value
is a member of a particular type class, or cast such a value to a type class
constrained type.

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]        |     -- the last words of T. S. Garp.



Reply via email to