[mercury-users] typeclass instance with functional dependency.

Maxime Van Assche mva at missioncriticalit.com
Tue Sep 8 18:52:05 AEST 2009


Hi,

In the following test, the compiler complains about "Error: unbound type variable Y in constraints on instance declaration.",
while there is a functional dependency, which should (from my understanding) bind that type.

Should this not throw an error?
And if so, can it be fixed easily?

Thanks,
Max.

:- module typeclass_test_2.

:- interface.

:- import_module io.

:- pred main(io::di, io::uo) is det.

:- implementation.

:- import_module string.
:- import_module int.

main(!IO) :-
     io.write_string("typeclass_test_2", !IO).



:- typeclass a(A, B) <= (A -> B) where
[
     (pred a1(A::in) is semidet),
     (pred a2(A::in, B::out) is semidet)
].

:- typeclass c(C) where
[
     (pred c(C::in) is semidet)
].


:- type x(X) ---> x(X).

% Error: unbound type variable Y in constraints on instance declaration.
:- instance c(x(X)) <= a(X, Y) where
[
     (c(x(X)) :-
         a1(X),
         a2(X, _Y)
     )
].

/*
% This workaround works, of course.
:- type x(X, Y) ---> x(X).

:- instance c(x(X, Y)) <= a(X, Y) where
[
     (c(x(X)) :-
         a1(X),
         a2(X, _Y)
     )
].

*/

:- end_module typeclass_test_2.
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list