[m-dev.] Ye Olde Subtyping Proposal
Fergus Henderson
fjh at cs.mu.OZ.AU
Mon Nov 18 17:26:24 AEDT 2002
On 18-Nov-2002, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> Fergus Henderson, Monday, 18 November 2002:
> >
> > I agree that abstract subtypes would be useful, but supporting them would
> > mean that the proposal was no longer just syntactic sugar, but instead added
> > a major new feature. This would require substantial changes to mode analysis
> > to implement. I'm not opposed to doing that in the long term, but in the
> > short term I think it would be better to support subtypes without abstract
> > subtypes.
>
> Why would it require major changes (forgive me if I'm a bit slow... it's one
> of those days)?
> Can't we just export the appropriate subtype and inst information in the
> .int file and leave it at that (with your structural-and-by-name approach)?
For concrete subtypes, sure. But for abstract subtypes, including that
information in the .int file would be wrong; it would mean that changing
the implementation of the module would change the .int file, in ways that
could cause other modules to no longer compile.
For example:
:- module fruit.
:- interface.
:- type fruit ---> apple ; orange ; lemon.
:- subtype citrus < fruit ---> orange ; lemon.
:- subtype favourite_fruit < fruit. % abstract
:- func my_favourite = favourite_fruit.
:- func your_favourite = favourite_fruit.
Suppose this is initially implemented as
:- implementation.
% no-one likes apples.
:- subtype favourite_fruit < fruit ---> orange ; lemon.
my_favourite = lemon.
your_favourite = orange.
and some other module uses this
:- module fruit_comparison.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module fruit.
main --> print("My favour fruit is "),
print(comparison(my_favourite, your_favourite)),
print(" your favourite fruit."), nl.
:- func comparison(citrus, citrus) = string.
comparison(orange, lemon) = "sweeter than".
comparison(lemon, orange) = "yellower than".
comparison(lemon, lemon) = "the same as".
comparison(orange, orange) = "the same as".
If the implementation of the fruit module is changed to
% revision 2: fixes issue that some people do like apples.
:- implementation.
:- subtype favourite_fruit < fruit ---> apple ; orange ; lemon.
my_favourite = apple.
your_favourite = orange.
then the fruit_comparison module will end up comparing apples with oranges,
which won't work.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list