Re: O'Haskell OOP Polymorphic Functions

At 2001-01-16 14:04, Tom Pledger wrote:
The subtyping (struct Derived < Base ...) makes the two instances overlap, with 'instance TheValue Derived' being strictly more specific than 'instance TheValue Base'. If the system preferred the less specific one, the more specific one would never be used.
This is quite similar to the way overlapping instances are handled when they occur via substitutions for type variables (e.g. 'instance C [Char]' is strictly more specific than 'instance C [a]') in implementations which support than language extension.
Subtyping-overlapping is quite different from type-substitution overlapping. Consider: struct B struct D1 < Base = a1 :: Int struct D2 < Base = a2 :: Int class TheValue a where theValue :: a -> Int instance TheValue B where theValue _ = 0 instance TheValue D1 where theValue _ = 1 instance TheValue D2 where theValue _ = 2 struct M < D1,D2 m = struct a1 = 0 a2 = 0 f = theValue m What's the value of f? -- Ashley Yakeley, Seattle WA

Ashley Yakeley writes: [...]
Subtyping-overlapping is quite different from type-substitution overlapping.
Different, but with some similarities.
Consider:
struct B
struct D1 < Base = a1 :: Int
struct D2 < Base = a2 :: Int
class TheValue a where theValue :: a -> Int instance TheValue B where theValue _ = 0 instance TheValue D1 where theValue _ = 1 instance TheValue D2 where theValue _ = 2
struct M < D1,D2
m = struct a1 = 0 a2 = 0
f = theValue m
What's the value of f?
Undefined, because neither of the overlapping instances is strictly more specific than the other. I hope that would cause a static error, anywhere that 'instance TheValue D1', 'instance TheValue D2', and 'struct M' are all in scope together. Here's a similar example using type-substitution overlapping: instance TheValue Char where ... instance Monad m => TheValue (m Char) where ... instance TheValue a => TheValue (Maybe a) where ... trouble = theValue (Just 'b') Regards, Tom
participants (2)
-
Ashley Yakeley
-
Tom Pledger