Subtyping for Mercury?
rwab1 at cam.sri.com
Tue Apr 15 00:45:33 AEST 1997
has anybody considered augmenting the Mercury type scheme with a
subtyping relation a la Modula 3? This would be very handy for
implementing OO support for Mercury.
Let's say I have a class foo with attributes foo_a_1 to foo_a_3 and
methods foo_m_1 to foo_m_4 (sorry about the boring names).
Now I want a subclass bar which inherits all of the above, but also
adds attributes bar_a_1 to bar_a_2 and methods bar_m_1 to bar_m3 and
overrides foo_m_1 with bar_m_4.
Anything which accepts a foo as a class should also accept a bar (but
not vice versa). Moreover, there should be a way of narrowing the type
of a bar object in order to access the hidden foo methods.
Maybe I'm missing something, but it's not obvious to me how I could
implement such a scheme in Mercury without having to also add my own
runtime type checking (which would (a) be a shame and (b) not be in the
Mercury style). If Mercury had subtyping and ADTs (i.e. classes) there
would, of course, be no problem!
More information about the users