[m-rev.] diff: add semidet modes for folds over arrays and hash tables

Julien Fischer juliensf at csse.unimelb.edu.au
Wed Jul 28 00:58:39 AEST 2010


Branches: main

Add semidet modes for folds over arrays and hash tables.

library/array.m:
library/hash_table.m:
library/version_array.m:
library/version_hash_table.m:
 	Add semidet modes (the occasional missing mostly-unique accumulator)
 	to fold style predicates.

NEWS:
 	Announce the additions.

Julien.

Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.529
diff -u -r1.529 NEWS
--- NEWS	19 Jul 2010 08:29:44 -0000	1.529
+++ NEWS	27 Jul 2010 14:52:22 -0000
@@ -3,6 +3,9 @@

  Changes to the Mercury standard library:

+* Semidet modes have been added for array.foldl/4, array.foldl2/6,
+  hash_table.fold/4, version_array.foldl/4, and version_hash_table.fold/4.
+
  * New predicates have been added to the assoc_list module, these are
    map_keys_only/3 map_values_only/3 and map_values/3.  They complement the
    functions of the same name.
Index: library/array.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/array.m,v
retrieving revision 1.173
diff -u -r1.173 array.m
--- library/array.m	20 Jul 2010 07:38:46 -0000	1.173
+++ library/array.m	27 Jul 2010 14:36:54 -0000
@@ -413,6 +413,9 @@
  :- mode array.foldl(pred(in, in, out) is det, in, in, out) is det.
  :- mode array.foldl(pred(in, mdi, muo) is det, in, mdi, muo) is det.
  :- mode array.foldl(pred(in, di, uo) is det, in, di, uo) is det.
+:- mode array.foldl(pred(in, in, out) is semidet, in, in, out) is semidet.
+:- mode array.foldl(pred(in, mdi, muo) is semidet, in, mdi, muo) is semidet.
+:- mode array.foldl(pred(in, di, uo) is semidet, in, di, uo) is semidet.

      % array.foldl2(Pr, Array, !X, !Y) is equivalent to
      %   list.foldl2(Pr, array.to_list(Array), !X, !Y)
@@ -425,6 +428,12 @@
      is det.
  :- mode array.foldl2(pred(in, in, out, di, uo) is det, in, in, out, di, uo)
      is det.
+:- mode array.foldl2(pred(in, in, out, in, out) is semidet, in,
+    in, out, in, out) is semidet.
+:- mode array.foldl2(pred(in, in, out, mdi, muo) is semidet, in,
+    in, out, mdi, muo) is semidet.
+:- mode array.foldl2(pred(in, in, out, di, uo) is semidet, in,
+    in, out, di, uo) is semidet.

      % array.foldr(Fn, Array, X) is equivalent to
      %   list.foldr(Fn, array.to_list(Array), X)
@@ -1698,6 +1707,9 @@
  :- mode foldl_0(pred(in, in, out) is det, in, in, in, in, out) is det.
  :- mode foldl_0(pred(in, mdi, muo) is det, in, in, in, mdi, muo) is det.
  :- mode foldl_0(pred(in, di, uo) is det, in, in, in, di, uo) is det.
+:- mode foldl_0(pred(in, in, out) is semidet, in, in, in, in, out) is semidet.
+:- mode foldl_0(pred(in, mdi, muo) is semidet, in, in, in, mdi, muo) is semidet.
+:- mode foldl_0(pred(in, di, uo) is semidet, in, in, in, di, uo) is semidet.

  foldl_0(P, A, I, Max, !X) :-
      ( Max < I ->
@@ -1707,7 +1719,7 @@
          foldl_0(P, A, I+1, Max, !X)
      ).

-% ---------------------------------------------------------------------------- %
+%-----------------------------------------------------------------------------%

  array.foldl2(P, A, X0, X, Y0, Y) :-
      array.foldl2_0(P, A, array.min(A), array.max(A), X0, X, Y0, Y).
@@ -1720,6 +1732,12 @@
      mdi, muo) is det.
  :- mode foldl2_0(pred(in, in, out, di, uo) is det, in, in, in, in, out,
      di, uo) is det.
+:- mode foldl2_0(pred(in, in, out, in, out) is semidet, in, in, in, in, out,
+    in, out) is semidet.
+:- mode foldl2_0(pred(in, in, out, mdi, muo) is semidet, in, in, in, in, out,
+    mdi, muo) is semidet.
+:- mode foldl2_0(pred(in, in, out, di, uo) is semidet, in, in, in, in, out,
+    di, uo) is semidet.

  foldl2_0(P, A, I, Max, X0, X, Y0, Y) :-
      ( Max < I ->
@@ -1730,7 +1748,7 @@
          foldl2_0(P, A, I+1, Max, X1, X, Y1, Y)
      ).

-% ---------------------------------------------------------------------------- %
+%-----------------------------------------------------------------------------%

  array.foldr(Fn, A, X) =
      foldr_0(Fn, A, X, array.min(A), array.max(A)).
@@ -1748,8 +1766,8 @@
          foldr_0(Fn, A, Fn(A ^ elem(I), X), Min, I - 1)
      ).

-% ---------------------------------------------------------------------------- %
-% ---------------------------------------------------------------------------- %
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

      % SAMsort (smooth applicative merge) invented by R.A. O'Keefe.
      %
Index: library/hash_table.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/hash_table.m,v
retrieving revision 1.22
diff -u -r1.22 hash_table.m
--- library/hash_table.m	20 Jul 2010 01:51:23 -0000	1.22
+++ library/hash_table.m	27 Jul 2010 14:42:09 -0000
@@ -192,8 +192,18 @@
      % Fold a predicate over the key-value bindings in a hash table.
      %
  :- pred fold(pred(K, V, T, T), hash_table(K, V), T, T).
-:- mode fold(in(pred(in, in, in, out) is det), hash_table_ui, in, out) is det.
-:- mode fold(in(pred(in, in, di, uo) is det), hash_table_ui, di, uo) is det.
+:- mode fold(in(pred(in, in, in, out) is det), hash_table_ui,
+    in, out) is det.
+:- mode fold(in(pred(in, in, mdi, muo) is det), hash_table_ui,
+    mdi, muo) is det.
+:- mode fold(in(pred(in, in, di, uo) is det), hash_table_ui,
+    di, uo) is det.
+:- mode fold(in(pred(in, in, in, out) is semidet), hash_table_ui,
+    in, out) is semidet.
+:- mode fold(in(pred(in, in, mdi, muo) is semidet), hash_table_ui,
+    mdi, muo) is semidet.
+:- mode fold(in(pred(in, in, di, uo) is semidet), hash_table_ui,
+    di, uo) is semidet.

  %-----------------------------------------------------------------------------%
  %-----------------------------------------------------------------------------%
@@ -636,7 +646,11 @@

  :- pred fold_p(pred(K, V, T, T), hash_table_alist(K, V), T, T).
  :- mode fold_p(pred(in, in, in, out) is det, in, in, out) is det.
+:- mode fold_p(pred(in, in, mdi, muo) is det, in, mdi, muo) is det.
  :- mode fold_p(pred(in, in, di, uo) is det, in, di, uo) is det.
+:- mode fold_p(pred(in, in, in, out) is semidet, in, in, out) is semidet.
+:- mode fold_p(pred(in, in, mdi, muo) is semidet, in, mdi, muo) is semidet.
+:- mode fold_p(pred(in, in, di, uo) is semidet, in, di, uo) is semidet.

  fold_p(_P, ht_nil, !A).
  fold_p(P, ht_cons(K, V, KVs), !A) :-
Index: library/version_array.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/version_array.m,v
retrieving revision 1.23
diff -u -r1.23 version_array.m
--- library/version_array.m	7 May 2010 03:12:25 -0000	1.23
+++ library/version_array.m	27 Jul 2010 14:45:50 -0000
@@ -135,6 +135,9 @@
  :- mode foldl(pred(in, in, out) is det, in, in, out) is det.
  :- mode foldl(pred(in, mdi, muo) is det, in, mdi, muo) is det.
  :- mode foldl(pred(in, di, uo) is det, in, di, uo) is det.
+:- mode foldl(pred(in, in, out) is semidet, in, in, out) is semidet.
+:- mode foldl(pred(in, mdi, muo) is semidet, in, mdi, muo) is semidet.
+:- mode foldl(pred(in, di, uo) is semidet, in, di, uo) is semidet.

      % foldr(F, A, X) is equivalent to list.foldr(F, list(A), Xs).
      %
@@ -243,6 +246,9 @@
  :- mode foldl_2(pred(in, in, out) is det, in, in, in, in, out) is det.
  :- mode foldl_2(pred(in, mdi, muo) is det, in, in, in, mdi, muo) is det.
  :- mode foldl_2(pred(in, di, uo) is det, in, in, in, di, uo) is det.
+:- mode foldl_2(pred(in, in, out) is semidet, in, in, in, in, out) is semidet.
+:- mode foldl_2(pred(in, mdi, muo) is semidet, in, in, in, mdi, muo) is semidet.
+:- mode foldl_2(pred(in, di, uo) is semidet, in, in, in, di, uo) is semidet.

  foldl_2(P, VA, Lo, Hi, !Acc) :-
      ( if Lo < Hi then
Index: library/version_hash_table.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/version_hash_table.m,v
retrieving revision 1.14
diff -u -r1.14 version_hash_table.m
--- library/version_hash_table.m	19 Jul 2010 06:59:08 -0000	1.14
+++ library/version_hash_table.m	27 Jul 2010 14:47:56 -0000
@@ -168,7 +168,11 @@
      %
  :- pred fold(pred(K, V, T, T), version_hash_table(K, V), T, T).
  :- mode fold(in(pred(in, in, in, out) is det), in, in, out) is det.
+:- mode fold(in(pred(in, in, mdi, muo) is det), in, mdi, muo) is det.
  :- mode fold(in(pred(in, in, di, uo) is det), in, di, uo) is det.
+:- mode fold(in(pred(in, in, in, out) is semidet), in, in, out) is semidet.
+:- mode fold(in(pred(in, in, mdi, muo) is semidet), in, mdi, muo) is semidet.
+:- mode fold(in(pred(in, in, di, uo) is semidet), in, di, uo) is semidet.

  %-----------------------------------------------------------------------------%
  %-----------------------------------------------------------------------------%
@@ -626,7 +630,11 @@

  :- pred fold_p(pred(K, V, T, T), hash_table_alist(K, V), T, T).
  :- mode fold_p(pred(in, in, in, out) is det, in, in, out) is det.
+:- mode fold_p(pred(in, in, mdi, muo) is det, in, mdi, muo) is det.
  :- mode fold_p(pred(in, in, di, uo) is det, in, di, uo) is det.
+:- mode fold_p(pred(in, in, in, out) is semidet, in, in, out) is semidet.
+:- mode fold_p(pred(in, in, mdi, muo) is semidet, in, mdi, muo) is semidet.
+:- mode fold_p(pred(in, in, di, uo) is semidet, in, di, uo) is semidet.

  fold_p(_P, ht_nil, !A).
  fold_p(P, ht_cons(K, V, KVs), !A) :-

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list