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

doug.auclair at logicaltypes.com doug.auclair at logicaltypes.com
Sat Jul 8 06:24:01 AEST 2006


Dear all,

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?

Sincerely,
Doug Auclair

---- begin module ---

:- module colours.

:- interface.

:- import_module io.

:- pred main(io::di, io::uo) is det.

:- implementation.

:- import_module var.
:- import_module list.
:- import_module require.
:- import_module string.

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).
colour_test(blue, Blue) :-
	init(Bluish),
	am_i(Bluish, Blue).
colour_test(indigo, Girls) :-
	init(Grrls),
	band(Grrls, Girls).

% :- type rainbow ---> red; orange; yellow; green; blue; indigo; violet.
:- type rainbow ---> red; blue; indigo.

:- pred primary_colour(var(rainbow)::ia) is semidet.
primary_colour(Xvar) :-
	freeze(Xvar, (pred(X::in) is semidet :-
	                   X = red /* ; X = yellow */ ; X = blue)).

:- pred some_other_colour(var(rainbow)::ia) is semidet.
some_other_colour(Xvar) :-
	freeze(Xvar, (pred(X::in) is semidet :- X = indigo)).

:- pred am_i(var(rainbow)::ia, rainbow::out) is semidet.
am_i(Xvar, blue) :-
	primary_colour(Xvar).

:- pred by_any_other_name(var(rainbow)::ia, rainbow::out) is semidet.
by_any_other_name(Xvar, red) :-
	primary_colour(Xvar).

:- pred band(var(rainbow)::ia, rainbow::out) is semidet.
band(Xvar, indigo) :-
	some_other_colour(Xvar).


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