[m-dev.] Foreign type compare and unification

Peter Schachte schachte at cs.mu.OZ.AU
Fri May 24 17:36:49 AEST 2002


On Fri, May 24, 2002 at 04:12:58PM +1000, Mark Brown wrote:
> > I don't think so.  As I understand it, you still want some random
> > distant piece of code to be able to declare that string is an instance
> > of comparable, and my code should benefit from it.
> 
> Urk, no.  I was making the unstated assumption that the instance
> declaration in question is visible in the given scope.

Ok, now just to be clear, are you suggesting that instance
declarations should have effect only where they're visible, or were
you just not considering the case I'm interested in where an unseen
instance declaration mysteriously affects my code?

> I would argue that
> > unless string is made an instance of comparable in the interface of
> > the module that defines string, or my code has such a declaration,
> > then my code should not consider string to be an instance of
> > comparable.  I'd rather get a compile-time error (not a link-time
> > error) if my code tries to compare two strings, or passes strings to a
> > predicate that does so.
> 
> Compile-time error is fine.  Link-time error is not as good, but still
> acceptable to me.  With default instance methods, though, you would get
> no error at all, but the behaviour of your program could change.  It is
> this that I am opposed to.

Again, to be sure we're talking about the same thing:  right now
someone can add an instance declaration to one module in the program
that would make another module fail to link properly.  Call that
problem 1.  I'm still not sure whether you propose to tolerate that
problem.  You are saying, though, that with default instance
declarations, someone could add a default instance declaration which
would make another module behave incorrectly.  Call that problem 2.
This is clearly worse, and you can't accept that.  I'd argue that both
are unacceptable.

But if the "defaultness" were attached to the *class* declaration
instead of the *instance* declaration, the second problem can't
happen, because a module can only be affected by visible classes,
though it can be affected by invisible instance declarations for
visible classes.  Ie, if the way to create a class that had every type
as an instance were to make a :- default_class declaration instead of
a :- class declaration, then changes to the declaration would only
affect modules in which it was visible.

I guess this would make the first problem worse, though, because an
instance declaration in some distant part of the code could override
the default methods for that type.  Instead of failing to link, the
code would misbehave.  So again, the first problem is significant; the
second needn't be a problem at all.

-- 
Peter Schachte              The fantastic advances in the field of
schachte at cs.mu.OZ.AU        communication constitute a grave danger to the
www.cs.mu.oz.au/~schachte/  privacy of the individual.
Phone: +61 3 8344 9166          -- Earl Warren 
--------------------------------------------------------------------------
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