O'Haskell OOP Polymorphic Functions

Tom Pledger [email protected]
Wed, 17 Jan 2001 11:04:40 +1300

Ashley Yakeley writes:
 > At 2001-01-16 13:18, Magnus Carlsson wrote:
 > >f1 = Just 3
 > >f2 = f3 = f4 = Nothing
 > So I've declared b = d, but 'theValue b' and 'theValue d' are different 
 > because theValue is looking at the static type of its argument?
 > What's to stop 'instance TheValue Base' applying in 'theValue d'?

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.