[mercury-users] A question on typeclasses

Julien Fischer juliensf at csse.unimelb.edu.au
Sun Apr 10 05:05:31 AEST 2011


Hi,

On Sat, 9 Apr 2011, Vladimir Gubarkov wrote:

> Why line XXX compiles well, but not YYY? I thought that types aaa & bbb are
> quite similar...

....

> :- type aaa ---> aaa(int).
>
> :- type bbb(T) ---> bbb(T).
> :- type bbb == bbb(int).
>
> :- instance qqqable(aaa) where [ func(qqq/1) is qqq_aaa ]. % XXX
> :- instance qqqable(bbb) where [ func(qqq/1) is qqq_aaa ]. % YYY
>
> qqq_aaa(A) = A.
>
> main(!IO) :- print(qqq(aaa(7)),!IO).
>
> The compilation shows:
>
> D:\stuff\test\mercury\solver>..\mmc_.bat t1 -E
> Making Mercury\int3s\t1.int3
> Making Mercury\ints\t1.int
> Making Mercury\cs\t1.c
> t1.m:019: In instance declaration for `t1.qqqable(t1.bbb(int))':
> t1.m:019:   the first arg is a type whose first arg is not a variable
> t1.m:019:   types in instance declarations must be functors with distinct
> t1.m:019:   variables as arguments
> Error: system command received signal 1.
> ** Error making `Mercury\cs\t1.c'.
>
> Could someone clarify why couldn't this work?

Expanding the equivalence type in YYY gives:

   :- instance qqqable(bbb(int)).

Instance argument types of the form bbb(int) are not (currently) allowed
in Mercury.  The argument type can only be a type with no arguments or a
polymorphic type whose arguments are all distinct type variables.
(See the ``Instance declarations'' of the reference manual for details.)

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