[mercury-users] Typeclass problem (bug, misunderstanding, oth er?)
Ralph Becket
rbeck at microsoft.com
Thu Aug 10 03:32:18 AEST 2000
> From: Fergus Henderson [mailto:fjh at cs.mu.OZ.AU]
>
> In order to typecheck a procedure call, one must rename apart the
> type variables in the called procedure's type declaration before
> unifying them with the calling procedure's type variables.
> I think that in making that deduction, you omitted the renaming
> apart step.
That's a good point. But I'm not sure it explains the following:
:- typeclass tc(T1, T2) where [
func e(T1) = T1,
func f(T1) = T2,
func g(T1, T2) = T2
].
:- func foo(T1) = T2 <= tc(T1, T2).
foo(A) = g(A, f(A)).
This will work fine. It's equivalent to
foo(A) = Z :-
X = A, % X:T1
Y = f(A), % Y:T2
Z = g(X, Y). % Z:T2
However,
:- func bar(T1) = T2 <= tc(T1, T2).
bar(A) = g(e(A), f(A)).
which is the same as
bar(A) = Z :-
X = e(A), % X:T1 surely the same type as A
% with the same relation to T2
Y = f(A), % Y:T2
Z = g(X, Y). % Z:T2
causes an unsatisfied typeclass constraint error.
Sorry to keep harping on about this one, but I am
just totally bemused. Can you go through the type
inference on this one line by line and point out
where the error is?
Cheers,
Ralph
begin 600 foo.m
M.BT@;6]D=6QE(&9O;RX-"CHM(&EN=&5R9F%C92X-"@T*.BT@='EP96-L87-S
M('1C*%0Q+"!4,BD@('=H97)E(%L-"B`@("!F=6YC(&4H5#$I(#T at 5#$L#0H)
M9G5N8R!F*%0Q*2`](%0R+`T*("`@(&9U;F, at 9RA4,2P at 5#(I(#T at 5#(-"ETN
M#0H-"CHM(&9U;F, at 9F]O*%0Q*2`](%0R(#P]('1C*%0Q+"!4,BDN#0H-"CHM
M(&9U;F, at 8F%R*%0Q*2`](%0R(#P]('1C*%0Q+"!4,BDN#0H-"CHM(&EM<&QE
M;65N=&%T:6]N+ at T*#0IF;V\H02D@/2!G*$$L(&8H02DI+ at T*#0IB87(H02D@
2/2!G*&4H02DL(&8H02DI+ at T*
`
end
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list