[mercury-users] Polymorphism / Type classes

Michael Day mikeday at corplink.com.au
Thu Jun 14 18:10:50 AEST 2001


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?

:- typeclass useful_factory(F) where
	[
		pred with_useful(pred(U, U), F, F) <= useful(U),
		mode with_useful(in(pred(di, uo) is det), di, uo) is det
	].

:- pred do_useful(F, F) <= useful_factory(F).
:- mode do_useful(di, uo) is det.

do_useful -->
	with_useful(do_stuff).	% type error

:- pred do_stuff(U, U) <= useful(U).
:- mode do_stuff(di, uo) is det.

do_stuff --> does lots of stuff.

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