[m-dev.] Typeclass problem
Mark Brown
mark at cs.mu.OZ.AU
Wed Apr 5 12:49:15 AEST 2006
On 05-Apr-2006, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> I want to define a type class like this:
>
> :- typeclass clausal(C, L) <= ((C -> L), literal(L)) where [
>
> func clauses(C::ia) = (list(clause(L))::oa) is det
>
> ].
>
> but for
>
> :- instance clausal(clause(L), L) <= literal(L).
>
> the compiler is complaining that
>
> clauses.m:053: Error: types in instance declarations must be functors
> with distinct variables as arguments: clausal(clause(_1), _1).
>
> Why is this restriction necessary when the second argument is a
> function of the first?
Indeed, why is it necessary at all? To avoid overlapping instances we
only need to ensure that no two instances can unify with each other; the
"functors with distinct variables" helps with this check, but is very
far from necessary.
This issue has been known for a long time, but fixing it is not trivial.
(Incidentally, functional dependencies won't help here. They make the
restrictions on instances tighter, not looser.)
Cheers,
Mark.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list