[mercury-users] Another place for existentials?

Mark Anthony BROWN dougl at cs.mu.OZ.AU
Thu Aug 3 13:41:41 AEST 2000


Michael Day writes:
> 
> > > :- instance match(list(T), U) <= match(T, U).	% error
> > 
> > This will fail to compile because it doesn't satisfy the restriction
> > on type class instances.  The reference manual details this restriction
> > and its rationale.  There is a simple workaround for it which should work
> > in this case:
> > 
> > 	:- type list_like(X) ---> list_like(X).
> > 	:- instance match(list(T), list_like(U)) <= match(T, U).
> 
> That works, but look at the consequences:
> 
> :- instance match(char, string).
> :- instance match(string, string).
> :- instance match(list(T), stream(Stream)) <= match(T, Stream).
> 
> Now we have match(char, string) and match(list(char), stream(string)). We
> can't use them together, which defeats the purpose of the type class.

By "use them together" I take it you mean calling something like

	:- pred p(A, B, T) <= (match(A, T), match(B, T)).

and passing it a char and a list(char) as the first two arguments.
The third argument could be neither wrapped nor unwrapped, so this is
indeed a case where the workaround fails.

Question: is the following meant to be legal Mercury?

	:- type stream(S) == S.

Perhaps the workaround could be refined to use this equivalence type instead
of the wrapper type.  I haven't tried this.

Cheers,
Mark.

--------------------------------------------------------------------------
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