[mercury-users] A question on typeclasses

Vladimir Gubarkov xonixx at gmail.com
Sun Apr 10 04:33:51 AEST 2011


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

:- module t1.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.

:- implementation.

:- typeclass qqqable(T) where [
func qqq(T) = T

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

Sincerely yours,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20110409/09614577/attachment.html>

More information about the users mailing list