[mercury-users] Superclasses and "solutions"
Kerry Raymond
kerry at dstc.edu.au
Tue Feb 26 17:24:31 AEDT 2002
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".
:- module try.
:- import_module std_util.
:- type a ---> aa.
:- type b ---> bb.
:- pred f_a(a).
f_a(aa).
:- pred f_b(b).
f_b(bb).
:- typeclass super(T) where [
pred f_x(T),
mode f_x(out) is multi
].
:- instance super(a) where [ pred(f_x/1) is f_a ].
:- instance super(b) where [ pred(f_x/1) is f_b ].
:- pred foo(int).
:- mode foo(in) is det.
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))
try.m:025: The unbound type variable(s) will be implicitly
try.m:025: bound to the builtin type `void'.
===========================================================================
Dr Kerry Raymond, Distinguished Research Fellow kerry at dstc.edu.au
CRC for Enterprise Distributed Systems Technology Ph: +61 7 3365 4310
University of Queensland 4072 Australia Fax: +61 7 3365 4311
===================================================== www.dstc.edu.au/kerry
--------------------------------------------------------------------------
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