[mercury-users] solver (tiny) example flounders?

Fergus Henderson fjh at csse.unimelb.edu.au
Fri Jul 21 09:28:28 AEST 2006


On 07-Jul-2006, doug.auclair at logicaltypes.com <doug.auclair at logicaltypes.com> wrote:
> I am learning about solver types with Mercury, so I built
> the following (admittedly tautological) example below.  
> It runs, but when it does, it issues the following warning 
> against my constraints:
> 
> "var.m: warning: goal floundered."
> 
> My program is below, the constraints I define are
> primary_colour/1 and some_other_colour/1.  What is my 
> misunderstanding of constraints that causes these
> goals to flounder?

For constraint programming, the paradigm is
"constrain and then generate" (as opposed to the
"generate and then test" paradigm).
You did the "constrain" step, but you missed the "generate" step.

See below for how to do that step.

> main(!IO) :-
> 	print("Hello, world!\n", !IO),
> 	(colour_test(blue, Blue),
> 	 colour_test(red, Red),
> 	 colour_test(indigo, Indigo) ->
> 	     format("
> Roses are %s,
> Violets are %s,
> I don't know if I like the %s girls;
> Do you?
> ", map((func(X) = Y :- Y = s(string(X))), [Red, Blue, Indigo]), !IO)
>          ;
> 	     error("Cannot constrain 'free' variable!")).
>
> :- pred colour_test(rainbow::in, rainbow::out) is semidet.
> colour_test(red, Red) :-
> 	init(Blood),
> 	by_any_other_name(Blood, Red).

Here you add a constraint on the variable "Blood"
(by_any_other_name/2 ends up calling freeze/2).
This constraint never gets resolved.

You need to write this as

	colour_test(red, Red) :-
		init(Blood),
		by_any_other_name(Blood, Red),
		generate_colour(Blood).

and similarly for the other clauses of colour_test/2,
where generate_colour/1 is defined as

        :- mode generate_colour(rainbow :: any >> ground) is nondet.
	generate_colour(red).
	generate_colour(blue).
	generate_colour(indigo).

Hope this helps!
Cheers,
    Fergus.

-- 
Fergus Henderson                    |  "I have always known that the pursuit
                                    |  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 csse.unimelb.edu.au
administrative address: owner-mercury-users at csse.unimelb.edu.au
unsubscribe: Address: mercury-users-request at csse.unimelb.edu.au Message: unsubscribe
subscribe:   Address: mercury-users-request at csse.unimelb.edu.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list