[mercury-users] overlapping instance declarations
Fergus Henderson
fjh at cs.mu.OZ.AU
Tue Aug 8 22:12:11 AEST 2000
On 06-Aug-2000, Michael Day <mcda at students.cs.mu.oz.au> wrote:
>
> Would it be possible, meaningful or useful to allow overlapping instance
> declarations, as long as they are in separate modules?
It would be possible, but there are some problems.
One problem is that doing so would significantly complicate intermodule
optimization; for example, our current implementation of intermodule
optimization would require major changes.
But probably the most serious problem is that it would complicate the
semantics. Currently, if we define the semantics using a typed
logic, where each value has an associated type, then instance
declarations can be viewed just as clauses. For example, given
:- typeclass foo(T) where [ pred bar(T) ].
the instance declarations
:- instance foo(int) where [ func(bar/1) is foo_bar ].
:- instance foo(list(T)) <= where [ func(bar/1) is list_bar ].
can be viewed as defining clauses for instance/1 and bar/1:
instance(foo(int)).
instance(foo(list(T))) :- instance(foo(T)).
bar(X) :- X:int, foo_bar(X).
bar(X) :- X:list(T), instance(foo(T)), list_bar(X).
Here `X:int' means "X has type `int'". Operationally you can think
of this as a dynamic type check.
This is a very direct, very simple way of specifying the declarative
and operational semantics of code using type classes.
But if we allow overlapping instance declarations, then this approach
breaks down.
--
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