[mercury-users] Another place for existentials?

Michael Day mcda at students.cs.mu.oz.au
Wed Aug 2 12:05:27 AEST 2000


> I then ran into problems when I wrote a predicate that required
> its argument to be a csp/2, but didn't care about the type of the
> node it was related to.  My first attempt was:
> 
> :- func solve(CSP) = CSP <= csp(CSP, _SomeNode).

Problems like this seem to plague the use of type classes with multiple
arguments; at least whenever I think I've found a nice abstraction I end
up requiring either a constraint with an unbound variable, or an instance
declaration with an unbound variable, or a constraint with a term...

% match is a type class for regular expressions
:- typeclass match(C, T) where [ ... ].

:- instance match(char, string).	% can match characters in strings
:- instance match(string, string).	% can match strings in strings
:- instance match(list(T), U) <= match(T, U).	% error
:- instance match(list(char), string).		% error

As always, match/2 became match/1, hard coded to use strings all the time.
Anyone managed to do anything useful with multiple argument type classes
in Mercury? That nice vector(Vector, Scalar) example Fergus posted has
similar problems when you don't care about one of the arguments, or care
too much:

:- pred mangle(T, T) <= vector(T, _Scalar).	% error
:- pred mangle(T, T) <= vector(T, float).	% error

Michael

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