[mercury-users] Typeclass instance variable types question.

Maxime Van Assche mva at missioncriticalit.com
Fri Dec 18 20:41:18 AEDT 2009


Hi,

Just a (naive?) question...

Why does the compiler requires a typeclass instance to have all of its types non-variable?
I understand that the goal is to be able to verify uniqueness.

However, as far as I can tell, requiring all the types non-variable is too conservative?
Only one of the instance types must be non-variable in order to verify uniqueness.
Of course, caution must be taken with functional dependencies constraints.

If this makes sense, it could simplify a lot of code, because forcing all non-variable types leads to useless types and instances.
A typical simple example:

:- typeclass x(A, B) <= y(B) where [ ... ].

:- typeclass y(B) where [...].

:- type a(A) ---> a(A).
:- type b(B) ---> b(B).

:- instance x(a(A), b(B)) where [...].

:- instance y(b(B)) <= y(B) where [just (de)construct b(B)...].



while, all I wanted to express was
:- instance x(a(A), B) <= (y(B)) where [...].

Of course, then one cannot define an instance x(A, b(B)), nor x(a(A), b(B)).


This is a simple example, but my real test case leads to many useless wrapping,
and makes things very complicated to read.


Thanks,

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