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

On 30-Jan-2001, Ashley Yakeley
At 2001-01-17 17:03, Lennart Augustsson wrote:
You seem to want dynamic type tests. ... 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?
class BaseClass s where
downcast_to_derived :: s -> Maybe Derived
--
Fergus Henderson

Tue, 30 Jan 2001 00:13:41 -0800, Ashley Yakeley
How do I define downcast?
You can use a non-standard module Dynamic present in ghc, hbc and Hugs (I don't know if it's compatible with O'Haskell). -- __("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZASTÊPCZA QRCZAK

On 30-Jan-2001, Marcin 'Qrczak' Kowalczyk
Tue, 30 Jan 2001 00:13:41 -0800, Ashley Yakeley
pisze: How do I define downcast?
You can use a non-standard module Dynamic present in ghc, hbc and Hugs (I don't know if it's compatible with O'Haskell).
That lets you downcast to specific ground types, but it doesn't
let you downcast to a type class constrained type variable.
--
Fergus Henderson
participants (3)
-
Ashley Yakeley
-
Fergus Henderson
-
qrczak@knm.org.pl