O'Haskell OOP Polymorphic Functions

Magnus Carlsson magnus@cse.ogi.edu
Tue, 16 Jan 2001 13:18:02 -0800


Ashley Yakeley writes:
 > At 2001-01-16 10:23, Magnus Carlsson wrote:
 > 
 > >You can use overloading for the definition of theValue instead:
 > >
 > >  class TheValue a where theValue :: a -> Maybe Int
 > >
 > >  instance TheValue Base    where theValue _ = Nothing
 > >  instance TheValue Derived where theValue x = Just (x.value)
 > 
 > Doesn't this imply that run-time type information is kept with the 
 > structs?

The overloading is resolved statically, so no run-time type
information is needed. 

 > 
 > Consider:
 > 
 > d :: Derived
 > d = struct
 >  value = 3
 > 
 > b :: Base
 > b = d
 > 
 > idb :: Base -> Base
 > idb x = x
 > 
 > f1 = theValue d
 > f2 = theValue b
 > f3 = theValue (idb d)
 > f4 = theValue (idb b)
 > 
 > What are the values of f1, f2, f3 & f4?

f1 = Just 3
f2 = f3 = f4 = Nothing

 > -- 
 > Ashley Yakeley, Seattle WA

/M