[mercury-users] overlapping instance declarations

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Aug 8 22:32:22 AEST 2000


On 06-Aug-2000, Michael Day <mcda at students.cs.mu.oz.au> wrote:
> 
> This could lead to ambiguity when attempting to satisfy a type class
> constraint if there are multiple instance declarations for that type in
> the current scope (imported from other modules). This could be treated
> similar to any other ambiguous situation; the user would have to module
> qualify the variable in question (somehow) to indicate which module's
> instance declaration to use. I can't quite envisage an appropriate syntax
> for that, it would seem to be related to type qualification...
> 
> 	% Bar is an int using fooable instance from quux?
> 	foo_method(Bar : int <= quux:fooable(int)),
> 
> 	% Bar using the instance fooable/1 from module quux?
> 	foo_method(Bar <= instance(quux:fooable/1)),

That doesn't seem like a good syntax, because the `quux:' module
qualifier on `quux:fooable' should surely be qualifying the class
`fooable', rather than the instance.  So I think

 	foo_method(Bar <= quux:instance(fooable/1)),

would be better.

But consider cases such as this:

	:- pred foo_method(T1, T2) <= fooable(T1, T2), fooable(T2, T1).

Here the instances in question are not associated with individual
arguments, but only with the predicate call as a whole.
So I think any syntax for module qualification of instance
declarations must reflect that.  Perhaps the syntax could be
something like this:

	<pred name>(<args>) where [ <module>.instance <instance> ... ]

For example:

	p(X, Y) :-
		foo_method(X:T1, Y:T2) where
			[module1.instance fooable(T1, T2),
			 module2.instance fooable(T2, T1)].
			 
However, personally I'm more in favour of keeping the semantics
simple by not allowing overlapping instance declarations.
If you want the flexibility that overlapping instance declarations
would give you, you can always use explicit argument passing to
pass records whose fields are higher-order terms.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list