[mercury-users] Polymorphism / Type classes
Ralph Becket
rbeck at microsoft.com
Thu Jun 14 21:04:14 AEST 2001
> From: Michael Day [mailto:mikeday at corplink.com.au]
> Sent: 14 June 2001 09:11
>
> The code below doesn't work, as the types for the predicate argument
of
> with_useful and do_stuff don't match up? Are too polymorphic? Anyway,
I
> can't seem to specify the right type class constraints to make this
work.
> Does anyone know if this is possible?
I tried converting to functions and renaming variables to see if that
gave any pointers:
:- module uf.
:- interface.
:- typeclass u(U) where [].
:- typeclass uf(F) where [
func wu(func(U) = U, F) = F <= u(U)
].
:- implementation.
:- func du(G) = G <= uf(G). % line 12
du(X) = wu(ds, X).
:- func ds(V) = V <= u(V).
ds(Y) = Y.
But all I got (with -E) was
uf.m:012: In function `uf:du/1':
uf.m:012: type error: unsatisfied typeclass constraint(s):
uf.m:012: uf:u(U).
uf.m:012: In function `uf:du/1':
uf.m:012: warning: unresolved polymorphism.
uf.m:012: The variable with an unbound type was:
uf.m:012: V_4 :: ((func U) = U)
uf.m:012: The unbound type variable(s) will be implicitly
uf.m:012: bound to the builtin type `void'.
The body of the clause contains a call to a polymorphic predicate,
but I can't determine which version should be called,
because the type variables listed above didn't get bound.
(I ought to tell you which call caused the problem, but I'm afraid
you'll have to work it out yourself. My apologies.)
I confess to being very confused too. Would it be possible for
someone in the know to post the type inference rules regarding
typeclasses? This sort of problem seems to crop up every time.
- Ralph
--------------------------------------------------------------------------
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