O'Haskell OOP Polymorphic Functions

Ashley Yakeley ashley@semantic.org
Tue, 30 Jan 2001 00:13:41 -0800

At 2001-01-17 17:03, Lennart Augustsson wrote:

>You seem to want dynamic type tests.  This is another feature, and
>sometimes a useful one.  But it requires carrying around types at

Yes. I tried to do that myself by adding a field, but it seems it can't 
be done.

>You might want to look at existential types; it is a similar feature.

I seem to run into a similar problem:

class BaseClass s
data Base = forall a. BaseClass a => Base a

class (BaseClass s) => DerivedClass s
data Derived = forall a. DerivedClass a => Derived a

upcast :: Derived -> Base
upcast (Derived d) = Base d

downcast :: Base -> Maybe Derived

How do I define downcast?

Ashley Yakeley, Seattle WA