[m-rev.] for review: use typeclass constraints to help resolve overloading

David Jeffery dgj at miscrit.be
Mon Jan 21 22:45:04 AEDT 2002


> There really ought to be some change to the language reference manual
> to document what you are trying to implement.

Does there really need to be a change to the reference manual? I think this
is really just a bug fix. Maybe I need to read the reference manual more
closely.

The problem that this is fixing is an artifact of the way that the final
stage of
overloading resolution is handled. As it stands, type class constraints
*are*
used to resolve overloading. The problem is that, after the overloading has
been resolved, all that is recorded in the pred_info is the types of
variables.
Then, in a later pass (during purity analysis), the compiler takes those
types
and tries to work out which pred_id each (unqualified) predicate name is
referring just by applying the types that are known at the call site.

In the case where there is more than one possible pred_id and the types
of the arguments are a match, the compiler aborts. (The idea being that
typecheck should have picked up the unresolved overloading). Of course,
in the case where you need to look at the type class constraints to
resolve overloading, the simple approach taken by the purity pass is not
enough.

The correct (but more arduous) solution to this problem would probably
be to do the work that purity is doing at the end of type checking, while
the type_assign_set is still there. That way, we wouldn't have to re-do
the work done by typecheck.

Hmmmmm, I just had a nasy thought: you can't get away with just looking
at each predicate call in isolation to resolve the overloading because in
general it isn't just the constraints from the 'head' of the caller that can
be used to eliminate the constraints from the callee. Instead, it is the
constraints from the head of the caller *and* any constraints produced
in the body of the caller.

Here's the rub: you can't know which constraints are produced in the
body until you've resolved overloading (so that you know which
predicates are called, and thus know which constraints are produced).
In other words, this final pass needs to do full-blown type checking,
including building up a type_assign_set.
The bottom line is that all of this stuff should be done at the end of
typecheck, while all the information is still hanging around.

Ack.


dgj

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list