On 07-Oct-1999, Marcin 'Qrczak' Kowalczyk <[EMAIL PROTECTED]> wrote:
> Tue, 5 Oct 1999 14:10:26 -0400 (EDT), Kevin Atkinson <[EMAIL PROTECTED]> pisze:
> 
> > 1) Dynamic types.  You can't cast up.  That is you can't recover the
> > original type from an object in a existential collection.  You need to
> > use a dynamic type library for that.  And the library proved with hugs
> > and ghc leaves a lot to be desired.  In an OO langauge all classes
> > automatically cary dynamic typing information.
> 
> Please, no. Don't require existentials to carry dynamic type
> information.

Well, existentials need to carry dynamic type information for
debugging purposes anyway.  And they may need it for GC too (though
there are other techniques that work too, such as tagging all data with
a bit indicating whether it is a pointer or not, or using conservative
collection).  So from an implementation complexity or efficiency
perspective, your argument here is very weak, IMHO.

> IMHO it's as ugly as Dynamic.

IMHO the concept of Dynamic is not at all ugly, although certainly the
realization of this concept in Hugs/ghc has a number of flaws.

> The concept of existentials works well without it. The essence of
> existential is that you don't care what type is inside as long as it
> has the stated properties. If you need it, I think this is either
> wrong design (e.g. the operation that would use the cast should be
> put inside the existential as a method) or some more fundamental lack
> in the Haskell's type system. Don't break existentials.

This is a much better argument.  I agree that we should not break
the current properties of polymorphic types, such as the
"Theorems For Free".  But we can supply support for dynamic type
class casts which should satisfy Kevin Atkinson (and others of similar
inclinations) without breaking those properties, by using the
`Typeable' type class.

> If you like this, you must also like Dynamic, so simply require the
> type under the existential to be Typeable and cast it through Dynamic.
> The effect would be the same, without a penalty to those that don't
> use it.

I strongly agree that the type should be required to be an
instance of `Typeable' for dynamic type casting to be used.

But `Dynamic' does not provide sufficient functionality.
There needs to be some way of performing casts to polymorphic
types and to class-constrained polymorphic types.
That is not possible with the current `Dynamic' interface in
Hugs/ghc.

Perhaps you would like to comment on my recent proposal
posted to this list for a `class_cast' function?

Another important difference is that currently in Hugs/ghc you need
to write instance declarations for `Typeable' manually.

> Sorry that I really can't explain well why I think that this concept
> does not fit into Haskell. I must have heard that such "typecase"
> is most often a bad design.

Doing a typecase on individual types is often a bad design, because
the typecase will often need to be modified to deal with new types
that come along later.  But doing a dynamic cast to a class-constrained
type won't suffer from the same problem, in general.

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