[mercury-users] determinism suprises

William Lee Irwin III wli at holomorphy.com
Sat Dec 9 18:32:31 AEDT 2000


On Sat, Dec 09, 2000 at 10:00:06AM +1100, Fergus Henderson wrote:
> A different ordering of the conjunction will be used for each mode,
> but conjunctions are only reordered to satisfy the modes, not to
> satisfy the determinism.

I can't be sure, then, whether this is from the compiler or not.

On Sat, Dec 09, 2000 at 10:00:06AM +1100, Fergus Henderson wrote:
> Could you post the code, or at least the mode declarations,
> for the predicates that this one calls?

I'm firing it off as a MIME attachment to this message. It's got some
moderately large tables in the module, so I've stripped down the module
to only the relevant predicates.


Cheers,
Bill
-- 
Die ganzen Zahlen hat der liebe Gott gemacht; alles andere ist Menschenwerk.
-- Leopold Kronecker
-------------- next part --------------
:- module pathology.
:- interface.
:- type color ---> white ; black.
:- type parity ---> even ; odd.
:- type file ---> a ; b ; c ; d ; e ; f ; g ; h.
:- type rank ---> first ; second ; third ; fourth ; fifth ; sixth ; seventh
					; eighth.
:- type squareindex ---> { file, rank }.

:- pred color(squareindex, color).
:- mode color(in, out) is det.
:- mode color(in, in) is semidet.
:- mode color(out, in) is multi.

:- implementation.

:- pred rank_parity(rank, parity).
:- mode rank_parity(in, in) is semidet.
:- mode rank_parity(in, out) is det.
:- mode rank_parity(out, in) is multi.
:- mode rank_parity(out, out) is multi.
rank_parity(first, odd). rank_parity(second, even). rank_parity(third, odd).
rank_parity(fourth, even). rank_parity(fifth, odd). rank_parity(sixth, even).
rank_parity(seventh, odd). rank_parity(eighth, even).

:- pred file_parity(file, parity).
:- mode file_parity(in, in) is semidet.
:- mode file_parity(in, out) is det.
:- mode file_parity(out, in) is multi.
:- mode file_parity(out, out) is multi.
file_parity(a,odd). file_parity(b,even). file_parity(c,odd).
file_parity(d,even). file_parity(e,odd).
file_parity(f,even). file_parity(g,odd). file_parity(h,even).

:- pred parity_to_color(parity, color).
:- mode parity_to_color(in, in) is semidet.
:- mode parity_to_color(in, out) is det.
:- mode parity_to_color(out, in) is det.
:- mode parity_to_color(out, out) is multi.
parity_to_color(even, black).
parity_to_color(odd, white).

:- pred add_parity(parity, parity, parity).
:- mode add_parity(in, in, out) is det.
:- mode add_parity(in, out, in) is det.
:- mode add_parity(out, in, in) is det.
:- mode add_parity(in, in, in) is semidet.
:- mode add_parity(out, out, in) is multi.
:- mode add_parity(out, in, out) is multi.
:- mode add_parity(in, out, out) is multi.
:- mode add_parity(out, out, out) is multi.
add_parity(even, even, even).
add_parity(even, odd, odd).
add_parity(odd, even, odd).
add_parity(odd, odd, even).

% What this really should have been was:
% color({File, Rank}, Color) :-
%	parity_to_color(Res, Color),
%	add_parity(FilePar, RankPar, Res),
%	file_parity(File, FilePar),
%	rank_parity(Rank, RankPar).
% but its determinism could not be correctly inferred by the compiler.
color({File, Rank}, Color) :-
	file_parity(File, FilePar),
	rank_parity(Rank, RankPar),
	add_parity(FilePar, RankPar, Res),
	parity_to_color(Res, Color).

:- end_module pathology.


More information about the users mailing list