[mercury-users] Another Mercury Modes Problem

Ralph Becket rafe at cs.mu.OZ.AU
Fri May 31 17:19:11 AEST 2002


Bob McKay, Friday, 31 May 2002:
> Aaaah, this is where my misunderstandings show. I had thought that
> the only space that got garbage collected was
> .data structures freed up by backtracking
> .dead data structures (ie inst dead)

Garbage is any data that is not reachable - that is, via a pointer on
the stack or a live local variable.  Garbage is collected and the space
is reused.

Glad to have cleared that one up.

> If that's a misunderstanding, my apologies. If so, then I probably
> don't need unique modes (but I probably _will_ need parametric
> bound modes, which on my understanding of the discussion suffer
> the same problem?)

Again, you don't really need parametric modes for what you want.

The maybe/1 type (or a variant you define yourself) is used 
where a particular field may or may not have been computed.

For example,

	:- type fitness
		--->	unevaluated
		;	evaluated(float).

	:- type individual
		--->	individual(
				stuff   :: stuff,
				fitness :: fitness
			).


	:- func new_individual(stuff) = individual.

	new_individual(X) =
		individual(X, unevaluated).


	:- func compute_fitness(individual) = individual.

	compute_fitness(I) =
		( I ^ fitness := evaluated(fitness_of_stuff(I ^ stuff)) ).


where compute_fitness/1 fills in the fitness field of an individual.

- 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