[mercury-users] errors with typeclasses

david wallin david at wallin.cx
Mon Oct 30 08:25:40 AEDT 2000


Hi all,

I've been fiddling around with typeclasses this weekend and get some 
strange errors that I hope you can help me straighten out.

First off I have these typeclasses :

:- typeclass gene(G) where [
			    func mutate_gene(G) = G
			   ].

:- typeclass chromosome(C) where [
				  func mutate_chromosome(C) = C,
				  func gene(C, int) = G <= gene(G),
				  pred set_gene(C, G) <= gene(G)
				 ].


:- typeclass population(P)
	where [
	       pred add_chromosome(P, C, P),
	       mode add_chromosome(in, in, out) is det,

	       pred remove_chromosome(P, C, P),
	       mode remove_chromosome(in, in, out) is det,

	       func get_chromosome(P, int) = C <= chromosome(C)
	      ].


Basically, I want a population to be any type of structure. I then 
tried to make a population instance :

:- instance population(list(C))
	where [
	       pred(add_chromosome/3) is list_add_chromosome,
	       pred(remove_chromosome/3) is list_remove_chromosome,
	       func(get_chromosome/2) is list_get_chromosome
	      ].

:- pred list_add_chromosome(list(C), C, list(C)) <= chromosome(C).
:- mode list_add_chromosome(di, in, uo) is det.

list_add_chromosome(ListIn, Chromosome, ListOut) :-
	ListOut = [Chromosome | ListIn].

:- pred list_remove_chromosome(list(C), C, list(C)) <= chromosome(C).
:- mode list_remove_chromosome(in, in, out) is det.

list_remove_chromosome(ListIn, Chromosome, ListOut) :-
	  list__delete_all(ListIn, Chromosome, ListOut).

:- func list_get_chromosome(list(C), int) = C <= chromosome(C).
:- mode list_get_chromosome(in, in) = out.


When I try to compile this I get the following error messages, which 
I don't know how to interpret.


gusga.m:086: In clause for type class method implementation:
gusga.m:086:   in unification of variable `HeadVar__3'
gusga.m:086:   and term `list_get_chromosome(HeadVar__1, HeadVar__2)':
gusga.m:086:   type error in argument(s) of functor `list_get_chromosome/2'.
gusga.m:086:   Argument 1 (HeadVar__1) has type `(list:list(C))',
gusga.m:086:   expected type was `(list:list(C))'.
gusga.m:085: In clause for type class method implementation:
gusga.m:085:   in argument 2 of call to predicate `list_remove_chromosome/3':
gusga.m:085:   type error: variable `HeadVar__2' has type `C',
gusga.m:085:   expected type was `C'.
gusga.m:085: In clause for type class method implementation:
gusga.m:085:   unsatisfiable typeclass constraint(s):
gusga.m:085:   `gusga:chromosome(C)'.
gusga.m:084: In clause for type class method implementation:
gusga.m:084:   in argument 2 of call to predicate `list_add_chromosome/3':
gusga.m:084:   type error: variable `HeadVar__2' has type `C',
gusga.m:084:   expected type was `C'.
gusga.m:084: In clause for type class method implementation:
gusga.m:084:   unsatisfiable typeclass constraint(s):
gusga.m:084:   `gusga:chromosome(C)'.


what am I doing wrong here ?


--david.



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