[m-rev.] diff: get the FD solver working again

Mark Brown mark at cs.mu.OZ.AU
Tue Dec 13 01:03:58 AEDT 2005


solvers/common/trunk/any_list.m:
	Add predicates and functions that are used by the FD solver, and
	were deleted by the recent import of extras/solver_types modules
	into this repository.

	Fix a bug in any_list.index0/3.

solvers/common/trunk/any_util.m:
	Don't import the list module, which isn't used.

Index: solvers/common/trunk/any_util.m
===================================================================
--- solvers/common/trunk/any_util.m	(revision 177)
+++ solvers/common/trunk/any_util.m	(working copy)
@@ -17,10 +17,6 @@
 
 :- interface.
 
-:- import_module list.
-
-
-
     % This predicate is useful for converting polymorphic non-solver type
     % values with inst any to inst ground (the compiler recognises that inst
     % any is equivalent to ground for non-polymorphic non-solver types).
Index: solvers/common/trunk/any_list.m
===================================================================
--- solvers/common/trunk/any_list.m	(revision 177)
+++ solvers/common/trunk/any_list.m	(working copy)
@@ -40,6 +40,9 @@
 :- mode any_list.append(ia, ia, oa) is det.
 :- mode any_list.append(oa, oa, ia) is multi.
 
+:- func any_list.append(list(T), list(T)) = list(T).
+:- mode any_list.append(ia, ia) = oa is det.
+
     % L1 ++ L2 = L :- append(L1, L2, L).
     %
 :- func any_list.(list(T) ++ list(T)) = list(T).
@@ -135,6 +138,8 @@
     %
 :- func any_list.reverse(list(T)::ia) = (list(T)::oa) is det.
 
+:- pred any_list.reverse(list(T)::ia, list(T)::oa) is det.
+
     % perm(List0, List):
     %   True iff `List' is a permutation of `List0'.
     %
@@ -149,6 +154,12 @@
     %   range, whereas the semidet preds fail if the index is out of
     %   range.
     %
+:- pred any_list.index0(list(T)::ia, int::in, T::oa) is semidet.
+:- pred any_list.index1(list(T)::ia, int::in, T::oa) is semidet.
+
+:- pred any_list.index0_det(list(T)::ia, int::in, T::oa) is det.
+:- pred any_list.index1_det(list(T)::ia, int::in, T::oa) is det.
+
 :- func any_list.index0_det(list(T)::ia, int::in) = (T::oa) is det.
 :- func any_list.index1_det(list(T)::ia, int::in) = (T::oa) is det.
 
@@ -235,6 +246,15 @@
 :- func any_list.map(func(X) = Y, list(X)) = list(Y).
 :- mode any_list.map(func(ia) = oa is det, ia) = oa is det.
 
+    % Same as map/3, but takes an impure pred.
+:- impure pred any_list.impure_map(impure pred(X, Y), list(X), list(Y)).
+:- mode any_list.impure_map(pred(ia, oa) is det, ia, oa) is det.
+:- mode any_list.impure_map(pred(ia, out) is det, ia, out) is det.
+:- mode any_list.impure_map(pred(in, oa) is det, in, oa) is det.
+:- mode any_list.impure_map(pred(ia, oa) is semidet, ia, oa) is semidet.
+:- mode any_list.impure_map(pred(ia, out) is semidet, ia, out) is semidet.
+:- mode any_list.impure_map(pred(in, oa) is semidet, in, oa) is semidet.
+
     % map2(T, L, M1, M2) uses the closure T
     % to transform the elements of L into the elements of M1 and M2.
 :- pred any_list.map2(pred(A, B, C), list(A), list(B), list(C)).
@@ -363,7 +383,16 @@
         list(C).
 :- mode any_list.map_corresponding(func(ia, ia) = oa is det, ia, ia) = oa 
         is det.
+:- mode any_list.map_corresponding(func(ia, in) = oa is det, ia, in) = oa 
+        is det.
+:- mode any_list.map_corresponding(func(in, ia) = oa is det, in, ia) = oa 
+        is det.
 
+:- pred any_list.map_corresponding(pred(A, B, C), list(A), list(B), list(C)).
+:- mode any_list.map_corresponding(pred(ia, ia, oa) is det, ia, ia, oa) is det.
+:- mode any_list.map_corresponding(pred(ia, in, oa) is det, ia, in, oa) is det.
+:- mode any_list.map_corresponding(pred(in, ia, oa) is det, in, ia, oa) is det.
+
     % map_corresponding3(F, [A1, .. An], [B1, .. Bn], [C1, .. Cn]) =
     %   [F(A1, B1, C1), .., F(An, Bn, Cn)].
     %
@@ -751,23 +780,40 @@
 any_list.append([X | Xs], Ys, [X | Zs]) :-
     any_list.append(Xs, Ys, Zs).
 
+any_list.append(Xs, Ys) = Zs :-
+    any_list.append(Xs, Ys, Zs).
+
 %-----------------------------------------------------------------------------%
 
-any_list.index0_det(List, N) = Elem :-
+any_list.index0([X | Xs], N, Y) :-
+    ( if N = 0 then Y = X else any_list.index0(Xs, N - 1, Y) ).
+
+any_list.index1([X | Xs], N, Y) :-
+    ( if N = 1 then Y = X else any_list.index1(Xs, N - 1, Y) ).
+
+any_list.index0_det(List, N, Elem) :-
     promise_pure (
         impure any_list.index0(List, N, Elem0)
     ->
         Elem = Elem0
     ;
-        error("index: index out of range")
+        error("any_list.index0_det: index out of range")
     ).
 
-:- pred any_list.index0(list(T)::ia, int::in, T::oa) is semidet.
+any_list.index1_det(List, N, Elem) :-
+    promise_pure (
+        impure any_list.index1(List, N, Elem0)
+    ->
+        Elem = Elem0
+    ;
+        error("any_list.index1_det: index out of range")
+    ).
 
-any_list.index0([X | Xs], N, Y) :-
-    ( if N = 0 then Y = X else any_list.index0(Xs, N, Y) ).
+any_list.index0_det(List, N) = Elem :-
+    any_list.index0_det(List, N, Elem).
 
-any_list.index1_det(List, N) = any_list.index0_det(List, N - 1).
+any_list.index1_det(List, N) = Elem :-
+    any_list.index1_det(List, N, Elem).
 
 %-----------------------------------------------------------------------------%
 
@@ -856,6 +902,9 @@
 any_list.reverse(L0) = L :-
     any_list.reverse_2(L0, [], L).
 
+any_list.reverse(L0, L) :-
+    any_list.reverse_2(L0, [], L).
+
 :- pred any_list.reverse_2(list(T)::ia, list(T)::ia, list(T)::oa)
         is det.
 
@@ -1019,6 +1068,11 @@
     call(P, H0, H),
     any_list.map(P, T0, T).
 
+any_list.impure_map(_, [],  []).
+any_list.impure_map(P, [H0 | T0], [H | T]) :-
+    impure call(P, H0, H),
+    impure any_list.impure_map(P, T0, T).
+
 any_list.map2(_, [],  [],  []).
 any_list.map2(P, [H0 | T0], [H1 | T1], [H2 | T2]) :-
     call(P, H0, H1, H2),
@@ -1066,6 +1120,15 @@
 any_list.map_corresponding(F, [A | As], [B | Bs]) =
     [F(A, B) | any_list.map_corresponding(F, As, Bs)].
 
+any_list.map_corresponding(_, [], [], []).
+any_list.map_corresponding(_, [], [_ | _], _) :-
+    error("map_corresponding/4: mismatched list arguments").
+any_list.map_corresponding(_, [_ | _], [], _) :-
+    error("map_corresponding/4: mismatched list arguments").
+any_list.map_corresponding(P, [A | As], [B | Bs], [C | Cs]) :-
+    P(A, B, C),
+    any_list.map_corresponding(P, As, Bs, Cs).
+
 any_list.map_corresponding3(F, As, Bs, Cs) =
     (
         As = [A | As0],
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list