[mercury-users] disadvantage of not using "any" mode?

Aditya Raj PATHANIA adityarp at students.cs.mu.OZ.AU
Wed Oct 22 13:52:03 AEST 2003


hi,
  thanks fergus for the solver code. was very useful. i'm still adapting
my code to fit that design.

> The most important point is that for constrained variables, you should
> use the inst "any".

i wanted to know if this is critical because i'm not really relying on the
modes to ascertain if the variable has one or multiple values. i have made
some changes to the code
that you had sent me. i have not used the inst "any". i wanted to know the
usefulness of doing this or the disadvantages that the following code may
have. it works at present.

reason being i'm still trying to learn using modes in mercury.

changed code follows...

:- solver type indexical_var
   ---> indexical_var(c_pointer).

:- pred min(indexical_var,int).
:- mode min(in,out) is det.
:- pred max(indexical_var,int).
:- mode max(in,out) is det.

:- pred leq(indexical_var,int).
:- mode leq(in,in) is nondet.
:- pred gt(indexical_var,int).
:- mode gt(in,in) is nondet.

:- pred print_labeling(list(indexical_var), io__state, io__state).
:- mode print_labeling(in, di, uo) is cc_multi.

:- pred labeling(list(indexical_var), list(indexical_var)).
:- mode labeling(in, out) is nondet.

print_labeling(Vars) -->
		unsorted_aggregate(labeling(Vars), print_solution).

:- pred print_solution(list(indexical_var), io__state, io__state).
:- mode print_solution(in, di, uo) is det.

print_solution(Vars) -->
		{ print_to_list(Vars,Thelist) },
		io__print(Thelist),
		io__nl.

:- pred print_to_list(list(indexical_var),list(int)).
:- mode print_to_list(in,out) is det.
print_to_list(IPlist,OPlist) :-
(
		IPlist = [],
		OPlist = []
	;
		IPlist = [V|Vs],
		min(V,Val), % we use min here primarily to obtain the
value of the variable
		print_to_list(Vs,OPlists),
		OPlist = [Val|OPlists]
).

labeling([], []).
labeling([V | Vs0], [V | Vs]) :-
		min(V,Min),
		max(V,Max),
		( if Min = Max then
			labeling(Vs0, Vs)
		  else
			label(V,Min,Vs0,Vs)
		).

:- pred label(indexical_var,int,list(indexical_var),list(indexical_var)).
:- mode label(in,in,in,out) is nondet.
:- pragma promise_pure(label/4).

label(V,Min,Vs0,Vs) :-
		(
		  leq(V,Min),
		  list__append([V],Vs0,NVs0),
		  list__append([V],Vs,NVs),
		  labeling(NVs0,NVs)
		;
		  gt(V,Min),
		  list__append([V],Vs0,NVs0),
		  list__append([V],Vs,NVs),
		  labeling(NVs0,NVs)
		).
--------------------------------------------------------------------------
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