[mercury-users] Superclasses and "solutions"
Fergus Henderson
fjh at cs.mu.OZ.AU
Tue Feb 26 18:15:56 AEDT 2002
On 26-Feb-2002, Kerry Raymond <kerry at dstc.edu.au> wrote:
> I am trying to represent some O-O models in Mercury and am having some
> difficulties finding the right Mercury approach to inheritance. I thought
> that typeclasses would be the right approach, but am encountering
> compilationerrors rejecting what I am doing. I would welcome some expert
> advice on what the problem is.
>
> To make life simpler, I've found the smallest program to illustrate the
> problem. I have two types, "a" and "b", and a common abstract supertype
> of them "super". Each of "a" and "b" implement a concrete method "f_a"
> and "f_b" which are linked to the abstract method "f_x" of super. Everything
> goes haywire when I attempt to call "solutions".
...
> foo(_) :- solutions((pred(X::out) is nondet:- f_x(X)),_List).
>
> The compiler does not like this call to solutions. It says:
>
> try.m:025: In predicate `try:foo/1':
> try.m:025: type error: unsatisfied typeclass constraint(s):
> try.m:025: try:super(T).
> try.m:025: In predicate `try:foo/1':
> try.m:025: warning: unresolved polymorphism.
> try.m:025: The variables with unbound types were:
> try.m:025: X :: T
> try.m:025: V_6 :: T
> try.m:025: V_5 :: (pred T)
> try.m:025: _List :: (list:list(T))
The problem here is that the compiler does not know what
the types of `X' and `_List' are. Since it does not know
what their type is, it can't determine which function to
call for `f_x'. This is why it complains about
"unsatisfied typeclass constraint".
If you add an explicit type qualifier, e.g. change "X" to "X `with_type` a",
then the error will go away; the call to solutions will then
find all the solutions to f_x(X) where X has type `a'.
Note that `solutions' only finds solutions to a predicate;
it can't be used to find all the types which are instances
of a particular type class.
Does that answer your question?
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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