[m-rev.] for review: allow arbitrary types in class constraints

David Overton dmo at cs.mu.OZ.AU
Fri May 10 09:35:56 AEST 2002


Hi DJ,

Sorry to take so long to get back to you.  I got side-tracked onto other
things.

On Mon, May 06, 2002 at 02:23:29PM +0100, David Jeffery wrote:
> I think you'll find problems with constraints like this on
> predicate signatures.
> 
> Try something of the form:
> 
> :- pred p(T, T) <= c(list(T)).
> :- mode p(in, in) is semidet.
> 
> and in the body 'p', do something which requires the
> type-info for 'T' to be extracted from the constraint. e.g.
> 
> p(X, Y) :-
>     ...,
>     X = Y. % This unification requires the type-info for T

Yes, running this test case give a segfault for 
	:- pred p(T, T) <= c(list(T)).
and
	:- pred p(T, T) <= (c(list(T)), c(T)).
but works for
	:- pred p(T, T) <= (c(T), c(list(T))).

> 
> You should probably also try a few other cases which
> involve using the type-info for constrained types.
> 
> Could you also add tests in the invalid/ directory for the
> cases where your new 'loop checks' get triggered in
> typecheck.m? Thanks.

The loop checks in typecheck.m and polymorphism.m don't cause type
errors when they are "triggered", they simply ensure that when there are
mutually dependent instance constraints, each constraint is only added
once.  An example of this is in the test case `recursive_instance_1'
which has instance declarations

	:- instance foo(int, list(T)) <= foo(list(int), T) where [...].

	:- instance foo(list(T), int) <= foo(T, list(int)) where [...].

Without the check, the compiler gets into an infinite loop when trying
to typecheck a call to a method in foo.  With the check, the code is
accepted by the type checker.


David
-- 
David Overton      Computer Science and Software Engineering
PhD Student        The University of Melbourne   +61 3 8344 9159
Research Fellow    Monash University (Clayton)   +61 3 9905 5779
--------------------------------------------------------------------------
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