[m-rev.] for review: improve support for folds over sets in stdlib

Julien Fischer juliensf at csse.unimelb.edu.au
Mon Nov 8 15:36:55 AEDT 2010


For review by anyone.

Support folds over sets with up to five accumulators in all the standard
library modules that provide sets.

Support mostly-unique and unique accumulators in set folds.
(These were provided in some set modules, but not in others.)

library/set.m:
library/set_bbbtree.m:
library/set_ctree234.m:
library/set_ordlist.m:
library/set_tree234.m:
library/set_unordlist.m:
 	Add predicates for fold over sets with up to five accumulators.

 	As per the coding standard, where an operation has both a
 	function version and a predicate version, the declaration for
 	the function version should occur first in stdlib modules.

 	Fix up overlong lines.

library/set_bbbtree.m:
 	Add an XXX regarding the implementation of fold.

library/list.m:
 	Add additional modes to list.foldl3/8, list.foldl4/10,
 	and list.foldl5/12 required by the above.

NEWS:
 	Announce the changes.

Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.541
diff -u -r1.541 NEWS
--- NEWS	5 Nov 2010 05:48:38 -0000	1.541
+++ NEWS	8 Nov 2010 04:35:01 -0000
@@ -28,12 +28,21 @@

    + We added a new predicate list.map3_foldl/7 which maps over a list producing
      three lists and one folded value.
+ 
+  + We added semidet modes with unique accumulators for list.foldl3/8,
+    list.foldl4/10, and list.foldl5/12.

  * We have added the predicates divide/4 and divide_by_set/4 to the tree_bitset
    module of the standard library.

  * We have added the predicate set_ctree234.member/2.

+* All of the modules in the standard library that implement the set ADT,
+  (set, set_ordlist, set_unordlist, set_bbbtree, set_tree234,
+  and set_ctree234), now support folding over sets with up to five
+  accumulators.  Modes that provide unique and mostly-unique accumulators
+  for set fold have also been added.
+
  Changes to the Mercury compiler:

  * Support for building and linking against frameworks on Mac OS X has
Index: library/list.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/list.m,v
retrieving revision 1.197
diff -u -r1.197 list.m
--- library/list.m	8 Nov 2010 03:43:43 -0000	1.197
+++ library/list.m	8 Nov 2010 04:35:01 -0000
@@ -803,6 +803,8 @@
      in, in, out, in, out, in, out) is semidet.
  :- mode list.foldl3(pred(in, in, out, in, out, mdi, muo) is semidet,
      in, in, out, in, out, mdi, muo) is semidet.
+:- mode list.foldl3(pred(in, in, out, in, out, di, uo) is semidet,
+    in, in, out, in, out, di, uo) is semidet.
  :- mode list.foldl3(pred(in, in, out, in, out, in, out) is nondet,
      in, in, out, in, out, in, out) is nondet.
  :- mode list.foldl3(pred(in, in, out, in, out, mdi, muo) is nondet,
@@ -833,6 +835,8 @@
      in, in, out, in, out, in, out, in, out) is semidet.
  :- mode list.foldl4(pred(in, in, out, in, out, in, out, mdi, muo) is semidet,
      in, in, out, in, out, in, out, mdi, muo) is semidet.
+:- mode list.foldl4(pred(in, in, out, in, out, in, out, di, uo) is semidet,
+    in, in, out, in, out, in, out, di, uo) is semidet.
  :- mode list.foldl4(pred(in, in, out, in, out, in, out, in, out) is nondet,
      in, in, out, in, out, in, out, in, out) is nondet.
  :- mode list.foldl4(pred(in, in, out, in, out, in, out, mdi, muo) is nondet,
@@ -860,6 +864,9 @@
  :- mode list.foldl5(pred(in, in, out, in, out, in, out, in, out, mdi, muo)
      is semidet,
      in, in, out, in, out, in, out, in, out, mdi, muo) is semidet.
+:- mode list.foldl5(pred(in, in, out, in, out, in, out, in, out, di, uo)
+    is semidet,
+    in, in, out, in, out, in, out, in, out, di, uo) is semidet.
  :- mode list.foldl5(pred(in, in, out, in, out, in, out, in, out, in, out)
      is nondet,
      in, in, out, in, out, in, out, in, out, in, out) is nondet.
Index: library/set.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/set.m,v
retrieving revision 1.87
diff -u -r1.87 set.m
--- library/set.m	8 Nov 2010 03:43:43 -0000	1.87
+++ library/set.m	8 Nov 2010 04:35:01 -0000
@@ -29,8 +29,8 @@

      % `set.init(Set)' is true iff `Set' is an empty set.
      %
-:- pred set.init(set(T)::uo) is det.
  :- func set.init = set(T).
+:- pred set.init(set(T)::uo) is det.

      % `set.list_to_set(List, Set)' is true iff `Set' is the set
      % containing only the members of `List'.
@@ -281,24 +281,61 @@
      in, out, di, uo) is det.
  :- mode set.fold2(pred(in, in, out, in, out) is semidet,
      in, in, out, in, out) is semidet.
+:- mode set.fold2(pred(in, in, out, mdi, muo) is semidet,
+    in, in, out, mdi, muo) is semidet.
+:- mode set.fold2(pred(in, in, out, di, uo) is semidet,
+    in, in, out, di, uo) is semidet.

  :- pred set.fold3(pred(T, A, A, B, B, C, C), set(T), A, A, B, B, C, C).
-:- mode set.fold3(pred(in, in, out, in, out, di, uo) is det, in,
-    in, out, in, out, di, uo) is det.
  :- mode set.fold3(pred(in, in, out, in, out, in, out) is det, in,
      in, out, in, out, in, out) is det.
+:- mode set.fold3(pred(in, in, out, in, out, mdi, muo) is det, in,
+    in, out, in, out, mdi, muo) is det.
+:- mode set.fold3(pred(in, in, out, in, out, di, uo) is det, in,
+    in, out, in, out, di, uo) is det.
  :- mode set.fold3(pred(in, in, out, in, out, in, out) is semidet, in,
      in, out, in, out, in, out) is semidet.
+:- mode set.fold3(pred(in, in, out, in, out, mdi, muo) is semidet, in,
+    in, out, in, out, mdi, muo) is semidet.
+:- mode set.fold3(pred(in, in, out, in, out, di, uo) is semidet, in,
+    in, out, in, out, di, uo) is semidet.

  :- pred set.fold4(pred(T, A, A, B, B, C, C, D, D), set(T), A, A, B, B,
-        C, C, D, D).
+    C, C, D, D).
  :- mode set.fold4(pred(in, in, out, in, out, in, out, in, out) is det, in,
      in, out, in, out, in, out, in, out) is det.
+:- mode set.fold4(pred(in, in, out, in, out, in, out, mdi, muo) is det, in,
+    in, out, in, out, in, out, mdi, muo) is det.
  :- mode set.fold4(pred(in, in, out, in, out, in, out, di, uo) is det, in,
      in, out, in, out, in, out, di, uo) is det.
  :- mode set.fold4(pred(in, in, out, in, out, in, out, in, out) is semidet, in,
      in, out, in, out, in, out, in, out) is semidet.
- 
+:- mode set.fold4(pred(in, in, out, in, out, in, out, mdi, muo) is semidet, in,
+    in, out, in, out, in, out, mdi, muo) is semidet.
+:- mode set.fold4(pred(in, in, out, in, out, in, out, di, uo) is semidet, in,
+    in, out, in, out, in, out, di, uo) is semidet.
+
+:- pred set.fold5(pred(T, A, A, B, B, C, C, D, D, E, E), set(T), A, A, B, B,
+    C, C, D, D, E, E).
+:- mode set.fold5(
+    pred(in, in, out, in, out, in, out, in, out, in, out) is det, 
+    in, in, out, in, out, in, out, in, out, in, out) is det.
+:- mode set.fold5(
+    pred(in, in, out, in, out, in, out, in, out, mdi, muo) is det, 
+    in, in, out, in, out, in, out, in, out, mdi, muo) is det.
+:- mode set.fold5(
+    pred(in, in, out, in, out, in, out, in, out, di, uo) is det, 
+    in, in, out, in, out, in, out, in, out, di, uo) is det.
+:- mode set.fold5(
+    pred(in, in, out, in, out, in, out, in, out, in, out) is semidet, 
+    in, in, out, in, out, in, out, in, out, in, out) is semidet.
+:- mode set.fold5(
+    pred(in, in, out, in, out, in, out, in, out, mdi, muo) is semidet, 
+    in, in, out, in, out, in, out, in, out, mdi, muo) is semidet.
+:- mode set.fold5(
+    pred(in, in, out, in, out, in, out, in, out, di, uo) is semidet, 
+    in, in, out, in, out, in, out, in, out, di, uo) is semidet.
+
      % set.divide(Pred, Set, TruePart, FalsePart):
      % TruePart consists of those elements of Set for which Pred succeeds;
      % FalsePart consists of those elements of Set for which Pred fails.
@@ -536,6 +573,9 @@
  set.fold4(F, S, !A, !B, !C, !D) :-
      list.foldl4(F, set.to_sorted_list(S), !A, !B, !C, !D).

+set.fold5(F, S, !A, !B, !C, !D, !E) :-
+    list.foldl5(F, set.to_sorted_list(S), !A, !B, !C, !D, !E).
+
  set.divide(P, Set, TruePart, FalsePart) :-
      set_ordlist.divide(P, Set, TruePart, FalsePart).

Index: library/set_bbbtree.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/set_bbbtree.m,v
retrieving revision 1.32
diff -u -r1.32 set_bbbtree.m
--- library/set_bbbtree.m	6 Mar 2007 05:48:34 -0000	1.32
+++ library/set_bbbtree.m	8 Nov 2010 04:35:01 -0000
@@ -1,10 +1,10 @@
-%------------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
  % vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
-%------------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
  % Copyright (C) 1995-1997, 1999-2006 The University of Melbourne.
  % This file may only be copied under the terms of the GNU Library General
  % Public License - see the file COPYING.LIB in the Mercury distribution.
-%------------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
  %
  % File: set_bbbtree.m.
  % Main authors: benyi.
@@ -12,8 +12,8 @@
  %
  % This module implements sets using bounded balanced binary trees.
  % 
-%------------------------------------------------------------------------------%
-%------------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

  :- module set_bbbtree.
  :- interface.
@@ -21,14 +21,14 @@
  :- import_module bool.
  :- import_module list.

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

  :- type set_bbbtree(T).

      % `set_bbbtree.init(Set)' returns an initialized empty set.
      %
-:- pred set_bbbtree.init(set_bbbtree(T)::uo) is det.
  :- func set_bbbtree.init = set_bbbtree(T).
+:- pred set_bbbtree.init(set_bbbtree(T)::uo) is det.

      % `set_bbbtree.empty(Set) is true iff `Set' is contains no elements.
      %
@@ -268,6 +268,89 @@
  :- mode set_bbbtree.filter_map(func(in) = out is semidet, in) = out is det.

  :- func set_bbbtree.fold(func(T1, T2) = T2, set_bbbtree(T1), T2) = T2.
+:- pred set_bbbtree.fold(pred(T1, T2, T2), set_bbbtree(T1), T2, T2).
+:- mode set_bbbtree.fold(pred(in, in, out) is det, in, in, out) is det.
+:- mode set_bbbtree.fold(pred(in, mdi, muo) is det, in, mdi, muo) is det.
+:- mode set_bbbtree.fold(pred(in, di, uo) is det, in, di, uo) is det.
+:- mode set_bbbtree.fold(pred(in, in, out) is semidet, in, in, out)
+    is semidet.
+:- mode set_bbbtree.fold(pred(in, mdi, muo) is semidet, in, mdi, muo)
+    is semidet.
+:- mode set_bbbtree.fold(pred(in, di, uo) is semidet, in, di, uo)
+    is semidet.
+
+:- pred set_bbbtree.fold2(pred(T1, T2, T2, T3, T3), set_bbbtree(T1),
+    T2, T2, T3, T3).
+:- mode set_bbbtree.fold2(pred(in, in, out, in, out) is det, in,
+    in, out, in, out) is det.
+:- mode set_bbbtree.fold2(pred(in, in, out, mdi, muo) is det, in,
+    in, out, mdi, muo) is det.
+:- mode set_bbbtree.fold2(pred(in, in, out, di, uo) is det, in,
+    in, out, di, uo) is det.
+:- mode set_bbbtree.fold2(pred(in, in, out, in, out) is semidet, in,
+    in, out, in, out) is semidet.
+:- mode set_bbbtree.fold2(pred(in, in, out, mdi, muo) is semidet, in,
+    in, out, mdi, muo) is semidet.
+:- mode set_bbbtree.fold2(pred(in, in, out, di, uo) is semidet, in,
+    in, out, di, uo) is semidet.
+
+:- pred set_bbbtree.fold3(pred(T1, T2, T2, T3, T3, T4, T4),
+    set_bbbtree(T1), T2, T2, T3, T3, T4, T4).
+:- mode set_bbbtree.fold3(pred(in, in, out, in, out, in, out) is det, in,
+    in, out, in, out, in, out) is det.
+:- mode set_bbbtree.fold3(pred(in, in, out, in, out, mdi, muo) is det, in,
+    in, out, in, out, mdi, muo) is det.
+:- mode set_bbbtree.fold3(pred(in, in, out, in, out, di, uo) is det, in,
+    in, out, in, out, di, uo) is det.
+:- mode set_bbbtree.fold3(pred(in, in, out, in, out, in, out) is semidet, in,
+    in, out, in, out, in, out) is semidet.
+:- mode set_bbbtree.fold3(pred(in, in, out, in, out, mdi, muo) is semidet, in,
+    in, out, in, out, mdi, muo) is semidet.
+:- mode set_bbbtree.fold3(pred(in, in, out, in, out, di, uo) is semidet, in,
+    in, out, in, out, di, uo) is semidet.
+
+:- pred set_bbbtree.fold4(pred(T1, T2, T2, T3, T3, T4, T4, T5, T5),
+    set_bbbtree(T1), T2, T2, T3, T3, T4, T4, T5, T5).
+:- mode set_bbbtree.fold4(
+    pred(in, in, out, in, out, in, out, in, out) is det, in,
+    in, out, in, out, in, out, in, out) is det.
+:- mode set_bbbtree.fold4(
+    pred(in, in, out, in, out, in, out, mdi, muo) is det, in,
+    in, out, in, out, in, out, mdi, muo) is det.
+:- mode set_bbbtree.fold4(
+    pred(in, in, out, in, out, in, out, di, uo) is det, in,
+    in, out, in, out, in, out, di, uo) is det.
+:- mode set_bbbtree.fold4(
+    pred(in, in, out, in, out, in, out, in, out) is semidet, in,
+    in, out, in, out, in, out, in, out) is semidet.
+:- mode set_bbbtree.fold4(
+    pred(in, in, out, in, out, in, out, mdi, muo) is semidet, in,
+    in, out, in, out, in, out, mdi, muo) is semidet.
+:- mode set_bbbtree.fold4(
+    pred(in, in, out, in, out, in, out, di, uo) is semidet, in,
+    in, out, in, out, in, out, di, uo) is semidet.
+
+:- pred set_bbbtree.fold5(
+    pred(T1, T2, T2, T3, T3, T4, T4, T5, T5, T6, T6),
+    set_bbbtree(T1), T2, T2, T3, T3, T4, T4, T5, T5, T6, T6).
+:- mode set_bbbtree.fold5(
+    pred(in, in, out, in, out, in, out, in, out, in, out) is det, in,
+    in, out, in, out, in, out, in, out, in, out) is det.
+:- mode set_bbbtree.fold5(
+    pred(in, in, out, in, out, in, out, in, out, mdi, muo) is det, in,
+    in, out, in, out, in, out, in, out, mdi, muo) is det.
+:- mode set_bbbtree.fold5(
+    pred(in, in, out, in, out, in, out, in, out, di, uo) is det, in,
+    in, out, in, out, in, out, in, out, di, uo) is det.
+:- mode set_bbbtree.fold5(
+    pred(in, in, out, in, out, in, out, in, out, in, out) is semidet, in,
+    in, out, in, out, in, out, in, out, in, out) is semidet.
+:- mode set_bbbtree.fold5(
+    pred(in, in, out, in, out, in, out, in, out, mdi, muo) is semidet, in,
+    in, out, in, out, in, out, in, out, mdi, muo) is semidet.
+:- mode set_bbbtree.fold5(
+    pred(in, in, out, in, out, in, out, in, out, di, uo) is semidet, in,
+    in, out, in, out, in, out, in, out, di, uo) is semidet.

  %------------------------------------------------------------------------------%
  %------------------------------------------------------------------------------%
@@ -319,7 +402,7 @@

  :- type set_bbbtree(T)
      --->    empty
-    ;   tree(T, int, set_bbbtree(T), set_bbbtree(T)).
+    ;       tree(T, int, set_bbbtree(T), set_bbbtree(T)).

      % `set_bbbtree.def_ratio(Ratio)' returns the ratio that is used in
      % deciding whether two trees require re-balancing.
@@ -825,14 +908,14 @@
          set_bbbtree.intersect_list_r(Intersect1, Sets, Ratio) :-
      set_bbbtree.intersect_r(Intersect0, Set, Intersect1, Ratio).

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

  % elem(x, A) and not elem(x, B) implies
  %
  % A difference B =
-%                   ( { elem(x, A) | x < a } difference { elem(x, B) | x < a } )
-%             union ( { a } )
-%             union ( { elem(x, A) | x > a } difference { elem(x, B) | x > a } )
+%               ( { elem(x, A) | x < a } difference { elem(x, B) | x < a } )
+%         union ( { a } )
+%         union ( { elem(x, A) | x > a } difference { elem(x, B) | x > a } )

  set_bbbtree.difference(SetA, SetB, Set) :-
      set_bbbtree.def_ratio(Ratio),
@@ -853,19 +936,19 @@
          set_bbbtree.concat4(LSet, RSet, V, Set, Ratio)
      ).

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

  set_bbbtree.subset(SetA, SetB) :-
      set_bbbtree.difference(SetA, SetB, Set),
      set_bbbtree.empty(Set).

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

  set_bbbtree.superset(SetA, SetB) :-
      set_bbbtree.subset(SetB, SetA).

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

      % Given X, L and R create a new tree who's root is X,
      % left subtree is L and right subtree is R.
@@ -880,7 +963,7 @@
      Tree0 = tree(X, N, L, R),
      unsafe_promise_unique(Tree0, Tree).

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

      % Single rotation to the left.
      %
@@ -1144,6 +1227,29 @@
          Set = R
      ).

+%-----------------------------------------------------------------------------%
+
+% XXX we should just traverse the tree directly instead of converting
+%     to a sorted list first.
+
+set_bbbtree.fold(F, S, A) = B :-
+    B = list.foldl(F, set_bbbtree.to_sorted_list(S), A).
+
+set_bbbtree.fold(P, S, !A) :-
+    list.foldl(P, set_bbbtree.to_sorted_list(S), !A).
+
+set_bbbtree.fold2(P, S, !A, !B) :-
+    list.foldl2(P, set_bbbtree.to_sorted_list(S), !A, !B).
+
+set_bbbtree.fold3(P, S, !A, !B, !C) :-
+    list.foldl3(P, set_bbbtree.to_sorted_list(S), !A, !B, !C).
+
+set_bbbtree.fold4(P, S, !A, !B, !C, !D) :-
+    list.foldl4(P, set_bbbtree.to_sorted_list(S), !A, !B, !C, !D).
+
+set_bbbtree.fold5(P, S, !A, !B, !C, !D, !E) :-
+    list.foldl5(P, set_bbbtree.to_sorted_list(S), !A, !B, !C, !D, !E).
+
  %--------------------------------------------------------------------------%
  %--------------------------------------------------------------------------%
  % Ralph Becket <rwab1 at cam.sri.com> 24/04/99
@@ -1199,5 +1305,6 @@
      S2 = set_bbbtree.list_to_set(list.filter_map(PF,
          set_bbbtree.to_sorted_list(S1))).

-set_bbbtree.fold(F, S, A) = B :-
-    B = list.foldl(F, set_bbbtree.to_sorted_list(S), A).
+%-----------------------------------------------------------------------------%
+:- end_module set_bbbtree.
+%-----------------------------------------------------------------------------%
Index: library/set_ctree234.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/set_ctree234.m,v
retrieving revision 1.11
diff -u -r1.11 set_ctree234.m
--- library/set_ctree234.m	8 Nov 2010 03:43:43 -0000	1.11
+++ library/set_ctree234.m	8 Nov 2010 04:35:01 -0000
@@ -63,8 +63,8 @@
      % `set_ctree234.is_member(Set, X, Result)' returns
      % `Result = yes' iff `X' is a member of `Set'.
      %
-:- pred set_ctree234.is_member(set_ctree234(T)::in, T::in, bool::out) is det.
  :- func set_ctree234.is_member(set_ctree234(T), T) = bool.
+:- pred set_ctree234.is_member(set_ctree234(T)::in, T::in, bool::out) is det.

      % `set_ctree234.contains(Set, X)' is true iff `X' is a member of `Set'.
      %
@@ -106,33 +106,33 @@
      % `set_ctree234.insert(X, Set0, Set)' is true iff `Set' is the union
      % of `Set0' and the set containing only `X'.
      %
+:- func set_ctree234.insert(T, set_ctree234(T)) = set_ctree234(T).
  :- pred set_ctree234.insert(T::in, set_ctree234(T)::in, set_ctree234(T)::out)
      is det.
-:- func set_ctree234.insert(T, set_ctree234(T)) = set_ctree234(T).

      % `set_ctree234.insert_list(Xs, Set0, Set)' is true iff `Set' is the
      % union of `Set0' and the set containing only the members of `Xs'.
      %
+:- func set_ctree234.insert_list(list(T), set_ctree234(T)) = set_ctree234(T).
  :- pred set_ctree234.insert_list(list(T)::in,
      set_ctree234(T)::in, set_ctree234(T)::out) is det.
-:- func set_ctree234.insert_list(list(T), set_ctree234(T)) = set_ctree234(T).

      % `set_ctree234.delete(X, Set0, Set)' is true iff `Set' is the
      % relative complement of `Set0' and the set containing only `X', i.e.
      % if `Set' is the set which contains all the elements of `Set0'
      % except `X'.
      %
+:- func set_ctree234.delete(T, set_ctree234(T)) = set_ctree234(T).
  :- pred set_ctree234.delete(T::in, set_ctree234(T)::in, set_ctree234(T)::out)
      is det.
-:- func set_ctree234.delete(T, set_ctree234(T)) = set_ctree234(T).

      % `set_ctree234.delete_list(Xs, Set0, Set)' is true iff `Set' is the
      % relative complement of `Set0' and the set containing only the members
      % of `Xs'.
      %
+:- func set_ctree234.delete_list(list(T), set_ctree234(T)) = set_ctree234(T).
  :- pred set_ctree234.delete_list(list(T)::in,
      set_ctree234(T)::in, set_ctree234(T)::out) is det.
-:- func set_ctree234.delete_list(list(T), set_ctree234(T)) = set_ctree234(T).

      % `set_ctree234.remove(X, Set0, Set)' is true iff `Set0' contains `X',
      % and `Set' is the relative complement of `Set0' and the set
@@ -160,32 +160,32 @@
      % `set_ctree234.union(SetA, SetB) = Set' is true iff `Set' is the union
      % of `SetA' and `SetB'.
      %
+:- func set_ctree234.union(set_ctree234(T), set_ctree234(T)) = set_ctree234(T).
  :- pred set_ctree234.union(set_ctree234(T)::in, set_ctree234(T)::in,
      set_ctree234(T)::out) is det.
-:- func set_ctree234.union(set_ctree234(T), set_ctree234(T)) = set_ctree234(T).

      % `set_ctree234.union_list(A, B)' is true iff `B' is the union of
      % all the sets in `A'
      %
+:- func set_ctree234.union_list(list(set_ctree234(T))) = set_ctree234(T).
  :- pred set_ctree234.union_list(list(set_ctree234(T))::in,
      set_ctree234(T)::out) is det.
-:- func set_ctree234.union_list(list(set_ctree234(T))) = set_ctree234(T).

      % `set_ctree234.power_union(A) = B' is true iff `B' is the union of
      % all the sets in `A'
      %
-:- pred set_ctree234.power_union(set_ctree234(set_ctree234(T))::in,
-    set_ctree234(T)::out) is det.
  :- func set_ctree234.power_union(set_ctree234(set_ctree234(T)))
      = set_ctree234(T).
+:- pred set_ctree234.power_union(set_ctree234(set_ctree234(T))::in,
+    set_ctree234(T)::out) is det.

      % `set_ctree234.intersect(SetA, SetB) = Set' is true iff `Set' is the
      % intersection of `SetA' and `SetB'.
      %
-:- pred set_ctree234.intersect(set_ctree234(T)::in, set_ctree234(T)::in,
-    set_ctree234(T)::out) is det.
  :- func set_ctree234.intersect(set_ctree234(T), set_ctree234(T))
      = set_ctree234(T).
+:- pred set_ctree234.intersect(set_ctree234(T)::in, set_ctree234(T)::in,
+    set_ctree234(T)::out) is det.

      % `set_ctree234.power_intersect(A, B)' is true iff `B' is the
      % intersection of all the sets in `A'.
@@ -202,19 +202,19 @@
      % set containing all the elements of `SetA' except those that
      % occur in `SetB'.
      %
-:- pred set_ctree234.difference(set_ctree234(T)::in, set_ctree234(T)::in,
-    set_ctree234(T)::out) is det.
  :- func set_ctree234.difference(set_ctree234(T), set_ctree234(T))
      = set_ctree234(T).
+:- pred set_ctree234.difference(set_ctree234(T)::in, set_ctree234(T)::in,
+    set_ctree234(T)::out) is det.

      % `set_ctree234.count(Set, Count)' is true iff `Set' has
      % `Count' elements.
      %
  :- func set_ctree234.count(set_ctree234(T)) = int.

+:- func set_ctree234.map(func(T1) = T2, set_ctree234(T1)) = set_ctree234(T2).
  :- pred set_ctree234.map(pred(T1, T2)::in(pred(in, out) is det),
      set_ctree234(T1)::in, set_ctree234(T2)::out) is det.
-:- func set_ctree234.map(func(T1) = T2, set_ctree234(T1)) = set_ctree234(T2).

  :- pred set_ctree234.filter_map(pred(T1, T2)::in(pred(in, out) is semidet),
      set_ctree234(T1)::in, set_ctree234(T2)::out) is det.
@@ -223,13 +223,89 @@
      = set_ctree234(T2).
  :- mode set_ctree234.filter_map(func(in) = out is semidet, in) = out is det.

-:- pred set_ctree234.fold(pred(T1, T2, T2)::in(pred(in, in, out) is det),
-    set_ctree234(T1)::in, T2::in, T2::out) is det.
  :- func set_ctree234.fold(func(T1, T2) = T2, set_ctree234(T1), T2) = T2.
+:- pred set_ctree234.fold(pred(T1, T2, T2), set_ctree234(T1), T2, T2).
+:- mode set_ctree234.fold(pred(in, in, out) is det, in, in, out) is det.
+:- mode set_ctree234.fold(pred(in, mdi, muo) is det, in, mdi, muo) is det.
+:- mode set_ctree234.fold(pred(in, di, uo) is det, in, di, uo) is det.
+:- mode set_ctree234.fold(pred(in, in, out) is semidet, in, in, out)
+    is semidet.
+:- mode set_ctree234.fold(pred(in, mdi, muo) is semidet, in, mdi, muo)
+    is semidet.
+:- mode set_ctree234.fold(pred(in, di, uo) is semidet, in, di, uo)
+    is semidet.

-:- pred set_ctree234.fold2(
-    pred(T1, T2, T2, T3, T3)::in(pred(in, in, out, in, out) is det),
-    set_ctree234(T1)::in, T2::in, T2::out, T3::in, T3::out) is det.
+:- pred set_ctree234.fold2(pred(T1, T2, T2, T3, T3), set_ctree234(T1),
+    T2, T2, T3, T3) is det.
+:- mode set_ctree234.fold2(pred(in, in, out, in, out) is det,
+    in, in, out, in, out) is det.
+:- mode set_ctree234.fold2(pred(in, in, out, mdi, muo) is det,
+    in, in, out, mdi, muo) is det.
+:- mode set_ctree234.fold2(pred(in, in, out, di, uo) is det,
+    in, in, out, di, uo) is det.
+:- mode set_ctree234.fold2(pred(in, in, out, in, out) is semidet,
+    in, in, out, in, out) is semidet.
+:- mode set_ctree234.fold2(pred(in, in, out, mdi, muo) is semidet,
+    in, in, out, mdi, muo) is semidet.
+:- mode set_ctree234.fold2(pred(in, in, out, di, uo) is semidet,
+    in, in, out, di, uo) is semidet.
+
+:- pred set_ctree234.fold3(
+    pred(T1, T2, T2, T3, T3, T4, T4), set_ctree234(T1),
+    T2, T2, T3, T3, T4, T4).
+:- mode set_ctree234.fold3(pred(in, in, out, in, out, in, out) is det, in,
+    in, out, in, out, in, out) is det.
+:- mode set_ctree234.fold3(pred(in, in, out, in, out, mdi, muo) is det, in,
+    in, out, in, out, mdi, muo) is det.
+:- mode set_ctree234.fold3(pred(in, in, out, in, out, di, uo) is det, in,
+    in, out, in, out, di, uo) is det.
+:- mode set_ctree234.fold3(pred(in, in, out, in, out, in, out) is semidet, in,
+    in, out, in, out, in, out) is semidet.
+:- mode set_ctree234.fold3(pred(in, in, out, in, out, mdi, muo) is semidet, in,
+    in, out, in, out, mdi, muo) is semidet.
+:- mode set_ctree234.fold3(pred(in, in, out, in, out, di, uo) is semidet, in,
+    in, out, in, out, di, uo) is semidet.
+
+:- pred set_ctree234.fold4(
+    pred(T1, T2, T2, T3, T3, T4, T4, T5, T5), set_ctree234(T1),
+    T2, T2, T3, T3, T4, T4, T5, T5).
+:- mode set_ctree234.fold4(pred(in, in, out, in, out, in, out, in, out) is det,
+    in, in, out, in, out, in, out, in, out) is det.
+:- mode set_ctree234.fold4(pred(in, in, out, in, out, in, out, mdi, muo) is det,
+    in, in, out, in, out, in, out, mdi, muo) is det.
+:- mode set_ctree234.fold4(pred(in, in, out, in, out, in, out, di, uo) is det,
+    in, in, out, in, out, in, out, di, uo) is det.
+:- mode set_ctree234.fold4(
+    pred(in, in, out, in, out, in, out, in, out) is semidet,
+    in, in, out, in, out, in, out, in, out) is semidet.
+:- mode set_ctree234.fold4(
+    pred(in, in, out, in, out, in, out, mdi, muo) is semidet,
+    in, in, out, in, out, in, out, mdi, muo) is semidet.
+:- mode set_ctree234.fold4(
+    pred(in, in, out, in, out, in, out, di, uo) is semidet,
+    in, in, out, in, out, in, out, di, uo) is semidet.
+
+:- pred set_ctree234.fold5(
+    pred(T1, T2, T2, T3, T3, T4, T4, T5, T5, T6, T6),
+    set_ctree234(T1), T2, T2, T3, T3, T4, T4, T5, T5, T6, T6).
+:- mode set_ctree234.fold5(
+    pred(in, in, out, in, out, in, out, in, out, in, out) is det,
+    in, in, out, in, out, in, out, in, out, in, out) is det.
+:- mode set_ctree234.fold5(
+    pred(in, in, out, in, out, in, out, in, out, mdi, muo) is det,
+    in, in, out, in, out, in, out, in, out, mdi, muo) is det.
+:- mode set_ctree234.fold5(
+    pred(in, in, out, in, out, in, out, in, out, di, uo) is det,
+    in, in, out, in, out, in, out, in, out, di, uo) is det.
+:- mode set_ctree234.fold5(
+    pred(in, in, out, in, out, in, out, in, out, in, out) is semidet,
+    in, in, out, in, out, in, out, in, out, in, out) is semidet.
+:- mode set_ctree234.fold5(
+    pred(in, in, out, in, out, in, out, in, out, mdi, muo) is semidet,
+    in, in, out, in, out, in, out, in, out, mdi, muo) is semidet.
+:- mode set_ctree234.fold5(
+    pred(in, in, out, in, out, in, out, in, out, di, uo) is semidet,
+    in, in, out, in, out, in, out, in, out, di, uo) is semidet.

      % set_ctree234.divide(Pred, Set, TruePart, FalsePart):
      % TruePart consists of those elements of Set for which Pred succeeds;
@@ -2148,9 +2224,20 @@
  set_ctree234.fold(Pred, ct(_, Tin), !A) :-
      set_ctree234.do_fold_pred(Pred, Tin, !A).

-:- pred set_ctree234.do_fold_pred(
-    pred(T1, T2, T2)::in(pred(in, in, out) is det),
-    set_tree234(T1)::in, T2::in, T2::out) is det.
+:- pred set_ctree234.do_fold_pred(pred(T1, T2, T2), set_tree234(T1),
+    T2, T2).
+:- mode set_ctree234.do_fold_pred(pred(in, in, out) is det, in,
+    in, out) is det.
+:- mode set_ctree234.do_fold_pred(pred(in, mdi, muo) is det, in,
+    mdi, muo) is det.
+:- mode set_ctree234.do_fold_pred(pred(in, di, uo) is det, in,
+    di, uo) is det.
+:- mode set_ctree234.do_fold_pred(pred(in, in, out) is semidet, in,
+    in, out) is semidet.
+:- mode set_ctree234.do_fold_pred(pred(in, mdi, muo) is semidet, in,
+    mdi, muo) is semidet.
+:- mode set_ctree234.do_fold_pred(pred(in, di, uo) is semidet, in,
+    di, uo) is semidet.

  set_ctree234.do_fold_pred(_Pred, empty, !A).
  set_ctree234.do_fold_pred(Pred, two(E, T0, T1), !A) :-
@@ -2203,8 +2290,19 @@
      set_ctree234.do_fold2_pred(Pred, Tin, !A, !B).

  :- pred set_ctree234.do_fold2_pred(
-    pred(T1, T2, T2, T3, T3)::in(pred(in, in, out, in, out) is det),
-    set_tree234(T1)::in, T2::in, T2::out, T3::in, T3::out) is det.
+    pred(T1, T2, T2, T3, T3), set_tree234(T1), T2, T2, T3, T3).
+:- mode set_ctree234.do_fold2_pred(pred(in, in, out, in, out) is det,
+    in, in, out, in, out) is det.
+:- mode set_ctree234.do_fold2_pred(pred(in, in, out, mdi, muo) is det,
+    in, in, out, mdi, muo) is det.
+:- mode set_ctree234.do_fold2_pred(pred(in, in, out, di, uo) is det,
+    in, in, out, di, uo) is det.
+:- mode set_ctree234.do_fold2_pred(pred(in, in, out, in, out) is semidet,
+    in, in, out, in, out) is semidet.
+:- mode set_ctree234.do_fold2_pred(pred(in, in, out, mdi, muo) is semidet,
+    in, in, out, mdi, muo) is semidet.
+:- mode set_ctree234.do_fold2_pred(pred(in, in, out, di, uo) is semidet,
+    in, in, out, di, uo) is semidet.

  set_ctree234.do_fold2_pred(_Pred, empty, !A, !B).
  set_ctree234.do_fold2_pred(Pred, two(E, T0, T1), !A, !B) :-
@@ -2226,6 +2324,145 @@
      Pred(E2, !A, !B),
      set_ctree234.do_fold2_pred(Pred, T3, !A, !B).

+set_ctree234.fold3(Pred, ct(_, Tin), !A, !B, !C) :-
+    set_ctree234.do_fold3_pred(Pred, Tin, !A, !B, !C).
+
+:- pred set_ctree234.do_fold3_pred(
+    pred(T1, T2, T2, T3, T3, T4, T4), set_tree234(T1),
+    T2, T2, T3, T3, T4, T4).
+:- mode set_ctree234.do_fold3_pred(
+    pred(in, in, out, in, out, in, out) is det,
+    in, in, out, in, out, in, out) is det.
+:- mode set_ctree234.do_fold3_pred(
+    pred(in, in, out, in, out, mdi, muo) is det,
+    in, in, out, in, out, mdi, muo) is det.
+:- mode set_ctree234.do_fold3_pred(
+    pred(in, in, out, in, out, di, uo) is det,
+    in, in, out, in, out, di, uo) is det.
+:- mode set_ctree234.do_fold3_pred(
+    pred(in, in, out, in, out, in, out) is semidet,
+    in, in, out, in, out, in, out) is semidet.
+:- mode set_ctree234.do_fold3_pred(
+    pred(in, in, out, in, out, mdi, muo) is semidet,
+    in, in, out, in, out, mdi, muo) is semidet.
+:- mode set_ctree234.do_fold3_pred(
+    pred(in, in, out, in, out, di, uo) is semidet,
+    in, in, out, in, out, di, uo) is semidet.
+
+set_ctree234.do_fold3_pred(_Pred, empty, !A, !B, !C).
+set_ctree234.do_fold3_pred(Pred, two(E, T0, T1), !A, !B, !C) :-
+    set_ctree234.do_fold3_pred(Pred, T0, !A, !B, !C),
+    Pred(E, !A, !B, !C),
+    set_ctree234.do_fold3_pred(Pred, T1, !A, !B, !C).
+set_ctree234.do_fold3_pred(Pred, three(E0, E1, T0, T1, T2), !A, !B, !C) :-
+    set_ctree234.do_fold3_pred(Pred, T0, !A, !B, !C),
+    Pred(E0, !A, !B, !C),
+    set_ctree234.do_fold3_pred(Pred, T1, !A, !B, !C),
+    Pred(E1, !A, !B, !C),
+    set_ctree234.do_fold3_pred(Pred, T2, !A, !B, !C).
+set_ctree234.do_fold3_pred(Pred, four(E0, E1, E2, T0, T1, T2, T3), !A, !B,
+        !C) :-
+    set_ctree234.do_fold3_pred(Pred, T0, !A, !B, !C),
+    Pred(E0, !A, !B, !C),
+    set_ctree234.do_fold3_pred(Pred, T1, !A, !B, !C),
+    Pred(E1, !A, !B, !C),
+    set_ctree234.do_fold3_pred(Pred, T2, !A, !B, !C),
+    Pred(E2, !A, !B, !C),
+    set_ctree234.do_fold3_pred(Pred, T3, !A, !B, !C).
+
+set_ctree234.fold4(Pred, ct(_, Tin), !A, !B, !C, !D) :-
+    set_ctree234.do_fold4_pred(Pred, Tin, !A, !B, !C, !D).
+
+:- pred set_ctree234.do_fold4_pred(
+    pred(T1, T2, T2, T3, T3, T4, T4, T5, T5), set_tree234(T1),
+    T2, T2, T3, T3, T4, T4, T5, T5).
+:- mode set_ctree234.do_fold4_pred(
+    pred(in, in, out, in, out, in, out, in, out) is det,
+    in, in, out, in, out, in, out, in, out) is det.
+:- mode set_ctree234.do_fold4_pred(
+    pred(in, in, out, in, out, in, out, mdi, muo) is det,
+    in, in, out, in, out, in, out, mdi, muo) is det.
+:- mode set_ctree234.do_fold4_pred(
+    pred(in, in, out, in, out, in, out, di, uo) is det,
+    in, in, out, in, out, in, out, di, uo) is det.
+:- mode set_ctree234.do_fold4_pred(
+    pred(in, in, out, in, out, in, out, in, out) is semidet,
+    in, in, out, in, out, in, out, in, out) is semidet.
+:- mode set_ctree234.do_fold4_pred(
+    pred(in, in, out, in, out, in, out, mdi, muo) is semidet,
+    in, in, out, in, out, in, out, mdi, muo) is semidet.
+:- mode set_ctree234.do_fold4_pred(
+    pred(in, in, out, in, out, in, out, di, uo) is semidet,
+    in, in, out, in, out, in, out, di, uo) is semidet.
+
+set_ctree234.do_fold4_pred(_Pred, empty, !A, !B, !C, !D).
+set_ctree234.do_fold4_pred(Pred, two(E, T0, T1), !A, !B, !C, !D) :-
+    set_ctree234.do_fold4_pred(Pred, T0, !A, !B, !C, !D),
+    Pred(E, !A, !B, !C, !D),
+    set_ctree234.do_fold4_pred(Pred, T1, !A, !B, !C, !D).
+set_ctree234.do_fold4_pred(Pred, three(E0, E1, T0, T1, T2), !A, !B, !C, !D) :-
+    set_ctree234.do_fold4_pred(Pred, T0, !A, !B, !C, !D),
+    Pred(E0, !A, !B, !C, !D),
+    set_ctree234.do_fold4_pred(Pred, T1, !A, !B, !C, !D),
+    Pred(E1, !A, !B, !C, !D),
+    set_ctree234.do_fold4_pred(Pred, T2, !A, !B, !C, !D).
+set_ctree234.do_fold4_pred(Pred, four(E0, E1, E2, T0, T1, T2, T3), !A, !B,
+        !C, !D) :-
+    set_ctree234.do_fold4_pred(Pred, T0, !A, !B, !C, !D),
+    Pred(E0, !A, !B, !C, !D),
+    set_ctree234.do_fold4_pred(Pred, T1, !A, !B, !C, !D),
+    Pred(E1, !A, !B, !C, !D),
+    set_ctree234.do_fold4_pred(Pred, T2, !A, !B, !C, !D),
+    Pred(E2, !A, !B, !C, !D),
+    set_ctree234.do_fold4_pred(Pred, T3, !A, !B, !C, !D).
+
+set_ctree234.fold5(Pred, ct(_, Tin), !A, !B, !C, !D, !E) :-
+    set_ctree234.do_fold5_pred(Pred, Tin, !A, !B, !C, !D, !E).
+
+:- pred set_ctree234.do_fold5_pred(
+    pred(T1, T2, T2, T3, T3, T4, T4, T5, T5, T6, T6), set_tree234(T1),
+    T2, T2, T3, T3, T4, T4, T5, T5, T6, T6).
+:- mode set_ctree234.do_fold5_pred(
+    pred(in, in, out, in, out, in, out, in, out, in, out) is det,
+    in, in, out, in, out, in, out, in, out, in, out) is det.
+:- mode set_ctree234.do_fold5_pred(
+    pred(in, in, out, in, out, in, out, in, out, mdi, muo) is det,
+    in, in, out, in, out, in, out, in, out, mdi, muo) is det.
+:- mode set_ctree234.do_fold5_pred(
+    pred(in, in, out, in, out, in, out, in, out, di, uo) is det,
+    in, in, out, in, out, in, out, in, out, di, uo) is det.
+:- mode set_ctree234.do_fold5_pred(
+    pred(in, in, out, in, out, in, out, in, out, in, out) is semidet,
+    in, in, out, in, out, in, out, in, out, in, out) is semidet.
+:- mode set_ctree234.do_fold5_pred(
+    pred(in, in, out, in, out, in, out, in, out, mdi, muo) is semidet,
+    in, in, out, in, out, in, out, in, out, mdi, muo) is semidet.
+:- mode set_ctree234.do_fold5_pred(
+    pred(in, in, out, in, out, in, out, in, out, di, uo) is semidet,
+    in, in, out, in, out, in, out, in, out, di, uo) is semidet.
+
+set_ctree234.do_fold5_pred(_Pred, empty, !A, !B, !C, !D, !E).
+set_ctree234.do_fold5_pred(Pred, two(E, T0, T1), !A, !B, !C, !D, !E) :-
+    set_ctree234.do_fold5_pred(Pred, T0, !A, !B, !C, !D, !E),
+    Pred(E, !A, !B, !C, !D, !E),
+    set_ctree234.do_fold5_pred(Pred, T1, !A, !B, !C, !D, !E).
+set_ctree234.do_fold5_pred(Pred, three(E0, E1, T0, T1, T2), !A, !B,
+        !C, !D, !E) :-
+    set_ctree234.do_fold5_pred(Pred, T0, !A, !B, !C, !D, !E),
+    Pred(E0, !A, !B, !C, !D, !E),
+    set_ctree234.do_fold5_pred(Pred, T1, !A, !B, !C, !D, !E),
+    Pred(E1, !A, !B, !C, !D, !E),
+    set_ctree234.do_fold5_pred(Pred, T2, !A, !B, !C, !D, !E).
+set_ctree234.do_fold5_pred(Pred, four(E0, E1, E2, T0, T1, T2, T3), !A, !B,
+        !C, !D, !E) :-
+    set_ctree234.do_fold5_pred(Pred, T0, !A, !B, !C, !D, !E),
+    Pred(E0, !A, !B, !C, !D, !E),
+    set_ctree234.do_fold5_pred(Pred, T1, !A, !B, !C, !D, !E),
+    Pred(E1, !A, !B, !C, !D, !E),
+    set_ctree234.do_fold5_pred(Pred, T2, !A, !B, !C, !D, !E),
+    Pred(E2, !A, !B, !C, !D, !E),
+    set_ctree234.do_fold5_pred(Pred, T3, !A, !B, !C, !D, !E).
+
  %------------------------------------------------------------------------------%

  set_ctree234.map(Pred, ct(_, TreeA), SetB) :-
Index: library/set_ordlist.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/set_ordlist.m,v
retrieving revision 1.33
diff -u -r1.33 set_ordlist.m
--- library/set_ordlist.m	8 Nov 2010 03:43:43 -0000	1.33
+++ library/set_ordlist.m	8 Nov 2010 04:35:01 -0000
@@ -226,6 +226,89 @@
  :- mode set_ordlist.filter_map(func(in) = out is semidet, in) = out is det.

  :- func set_ordlist.fold(func(T1, T2) = T2, set_ordlist(T1), T2) = T2.
+:- pred set_ordlist.fold(pred(T1, T2, T2), set_ordlist(T1), T2, T2).
+:- mode set_ordlist.fold(pred(in, in, out) is det, in, in, out) is det.
+:- mode set_ordlist.fold(pred(in, mdi, muo) is det, in, mdi, muo) is det.
+:- mode set_ordlist.fold(pred(in, di, uo) is det, in, di, uo) is det.
+:- mode set_ordlist.fold(pred(in, in, out) is semidet, in, in, out)
+    is semidet.
+:- mode set_ordlist.fold(pred(in, mdi, muo) is semidet, in, mdi, muo)
+    is semidet.
+:- mode set_ordlist.fold(pred(in, di, uo) is semidet, in, di, uo)
+    is semidet.
+
+:- pred set_ordlist.fold2(pred(T1, T2, T2, T3, T3), set_ordlist(T1),
+    T2, T2, T3, T3).
+:- mode set_ordlist.fold2(pred(in, in, out, in, out) is det, in,
+    in, out, in, out) is det.
+:- mode set_ordlist.fold2(pred(in, in, out, mdi, muo) is det, in,
+    in, out, mdi, muo) is det.
+:- mode set_ordlist.fold2(pred(in, in, out, di, uo) is det, in,
+    in, out, di, uo) is det.
+:- mode set_ordlist.fold2(pred(in, in, out, in, out) is semidet, in,
+    in, out, in, out) is semidet.
+:- mode set_ordlist.fold2(pred(in, in, out, mdi, muo) is semidet, in,
+    in, out, mdi, muo) is semidet.
+:- mode set_ordlist.fold2(pred(in, in, out, di, uo) is semidet, in,
+    in, out, di, uo) is semidet.
+
+:- pred set_ordlist.fold3(pred(T1, T2, T2, T3, T3, T4, T4),
+    set_ordlist(T1), T2, T2, T3, T3, T4, T4).
+:- mode set_ordlist.fold3(pred(in, in, out, in, out, in, out) is det, in,
+    in, out, in, out, in, out) is det.
+:- mode set_ordlist.fold3(pred(in, in, out, in, out, mdi, muo) is det, in,
+    in, out, in, out, mdi, muo) is det.
+:- mode set_ordlist.fold3(pred(in, in, out, in, out, di, uo) is det, in,
+    in, out, in, out, di, uo) is det.
+:- mode set_ordlist.fold3(pred(in, in, out, in, out, in, out) is semidet, in,
+    in, out, in, out, in, out) is semidet.
+:- mode set_ordlist.fold3(pred(in, in, out, in, out, mdi, muo) is semidet, in,
+    in, out, in, out, mdi, muo) is semidet.
+:- mode set_ordlist.fold3(pred(in, in, out, in, out, di, uo) is semidet, in,
+    in, out, in, out, di, uo) is semidet.
+
+:- pred set_ordlist.fold4(pred(T1, T2, T2, T3, T3, T4, T4, T5, T5),
+    set_ordlist(T1), T2, T2, T3, T3, T4, T4, T5, T5).
+:- mode set_ordlist.fold4(
+    pred(in, in, out, in, out, in, out, in, out) is det, in,
+    in, out, in, out, in, out, in, out) is det.
+:- mode set_ordlist.fold4(
+    pred(in, in, out, in, out, in, out, mdi, muo) is det, in,
+    in, out, in, out, in, out, mdi, muo) is det.
+:- mode set_ordlist.fold4(
+    pred(in, in, out, in, out, in, out, di, uo) is det, in,
+    in, out, in, out, in, out, di, uo) is det.
+:- mode set_ordlist.fold4(
+    pred(in, in, out, in, out, in, out, in, out) is semidet, in,
+    in, out, in, out, in, out, in, out) is semidet.
+:- mode set_ordlist.fold4(
+    pred(in, in, out, in, out, in, out, mdi, muo) is semidet, in,
+    in, out, in, out, in, out, mdi, muo) is semidet.
+:- mode set_ordlist.fold4(
+    pred(in, in, out, in, out, in, out, di, uo) is semidet, in,
+    in, out, in, out, in, out, di, uo) is semidet.
+
+:- pred set_ordlist.fold5(
+    pred(T1, T2, T2, T3, T3, T4, T4, T5, T5, T6, T6),
+    set_ordlist(T1), T2, T2, T3, T3, T4, T4, T5, T5, T6, T6).
+:- mode set_ordlist.fold5(
+    pred(in, in, out, in, out, in, out, in, out, in, out) is det, in,
+    in, out, in, out, in, out, in, out, in, out) is det.
+:- mode set_ordlist.fold5(
+    pred(in, in, out, in, out, in, out, in, out, mdi, muo) is det, in,
+    in, out, in, out, in, out, in, out, mdi, muo) is det.
+:- mode set_ordlist.fold5(
+    pred(in, in, out, in, out, in, out, in, out, di, uo) is det, in,
+    in, out, in, out, in, out, in, out, di, uo) is det.
+:- mode set_ordlist.fold5(
+    pred(in, in, out, in, out, in, out, in, out, in, out) is semidet, in,
+    in, out, in, out, in, out, in, out, in, out) is semidet.
+:- mode set_ordlist.fold5(
+    pred(in, in, out, in, out, in, out, in, out, mdi, muo) is semidet, in,
+    in, out, in, out, in, out, in, out, mdi, muo) is semidet.
+:- mode set_ordlist.fold5(
+    pred(in, in, out, in, out, in, out, in, out, di, uo) is semidet, in,
+    in, out, in, out, in, out, in, out, di, uo) is semidet.

      % set_ordlist.divide(Pred, Set, TruePart, FalsePart):
      % TruePart consists of those elements of Set for which Pred succeeds;
@@ -492,6 +575,26 @@
      list.length(Set, Count).

  %-----------------------------------------------------------------------------%
+
+set_ordlist.fold(F, S, A) = B :-
+    B = list.foldl(F, set_ordlist.to_sorted_list(S), A).
+
+set_ordlist.fold(P, S, !A) :-
+    list.foldl(P, set_ordlist.to_sorted_list(S), !A).
+
+set_ordlist.fold2(P, S, !A, !B) :-
+    list.foldl2(P, set_ordlist.to_sorted_list(S), !A, !B).
+
+set_ordlist.fold3(P, S, !A, !B, !C) :-
+    list.foldl3(P, set_ordlist.to_sorted_list(S), !A, !B, !C).
+
+set_ordlist.fold4(P, S, !A, !B, !C, !D) :-
+    list.foldl4(P, set_ordlist.to_sorted_list(S), !A, !B, !C, !D).
+
+set_ordlist.fold5(P, S, !A, !B, !C, !D, !E) :-
+    list.foldl5(P, set_ordlist.to_sorted_list(S), !A, !B, !C, !D, !E).
+
+%-----------------------------------------------------------------------------%
  %-----------------------------------------------------------------------------%
  % Ralph Becket <rwab1 at cam.sri.com> 24/04/99
  %   Function forms added.
@@ -548,9 +651,6 @@
      S2 = set_ordlist.list_to_set(list.filter_map(PF,
          set_ordlist.to_sorted_list(S1))).

-set_ordlist.fold(F, S, A) = B :-
-    B = list.foldl(F, set_ordlist.to_sorted_list(S), A).
-
  set_ordlist.divide(Pred, sol(Set), sol(TruePart), sol(FalsePart)) :-
      % The calls to reverse allow us to make divide_2 tail recursive.
      % This costs us a higher constant factor, but allows divide to work
Index: library/set_tree234.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/set_tree234.m,v
retrieving revision 1.13
diff -u -r1.13 set_tree234.m
--- library/set_tree234.m	8 Nov 2010 03:43:43 -0000	1.13
+++ library/set_tree234.m	8 Nov 2010 04:35:01 -0000
@@ -51,8 +51,8 @@
      % `set_tree234.is_member(Set, X, Result)' returns
      % `Result = yes' iff `X' is a member of `Set'.
      %
-:- pred set_tree234.is_member(set_tree234(T)::in, T::in, bool::out) is det.
  :- func set_tree234.is_member(set_tree234(T), T) = bool.
+:- pred set_tree234.is_member(set_tree234(T)::in, T::in, bool::out) is det.

      % `set_tree234.contains(Set, X)' is true iff `X' is a member of `Set'.
      %
@@ -92,33 +92,33 @@
      % `set_tree234.insert(X, Set0, Set)' is true iff `Set' is the union
      % of `Set0' and the set containing only `X'.
      %
+:- func set_tree234.insert(T, set_tree234(T)) = set_tree234(T).
  :- pred set_tree234.insert(T::in, set_tree234(T)::in, set_tree234(T)::out)
      is det.
-:- func set_tree234.insert(T, set_tree234(T)) = set_tree234(T).

      % `set_tree234.insert_list(Xs, Set0, Set)' is true iff `Set' is the
      % union of `Set0' and the set containing only the members of `Xs'.
      %
+:- func set_tree234.insert_list(list(T), set_tree234(T)) = set_tree234(T).
  :- pred set_tree234.insert_list(list(T)::in,
      set_tree234(T)::in, set_tree234(T)::out) is det.
-:- func set_tree234.insert_list(list(T), set_tree234(T)) = set_tree234(T).

      % `set_tree234.delete(X, Set0, Set)' is true iff `Set' is the
      % relative complement of `Set0' and the set containing only `X', i.e.
      % if `Set' is the set which contains all the elements of `Set0'
      % except `X'.
      %
+:- func set_tree234.delete(T, set_tree234(T)) = set_tree234(T).
  :- pred set_tree234.delete(T::in, set_tree234(T)::in, set_tree234(T)::out)
      is det.
-:- func set_tree234.delete(T, set_tree234(T)) = set_tree234(T).

      % `set_tree234.delete_list(Xs, Set0, Set)' is true iff `Set' is the
      % relative complement of `Set0' and the set containing only the members
      % of `Xs'.
      %
+:- func set_tree234.delete_list(list(T), set_tree234(T)) = set_tree234(T).
  :- pred set_tree234.delete_list(list(T)::in,
      set_tree234(T)::in, set_tree234(T)::out) is det.
-:- func set_tree234.delete_list(list(T), set_tree234(T)) = set_tree234(T).

      % `set_tree234.remove(X, Set0, Set)' is true iff `Set0' contains `X',
      % and `Set' is the relative complement of `Set0' and the set
@@ -146,31 +146,30 @@
      % `set_tree234.union(SetA, SetB) = Set' is true iff `Set' is the union
      % of `SetA' and `SetB'.
      %
+:- func set_tree234.union(set_tree234(T), set_tree234(T)) = set_tree234(T).
  :- pred set_tree234.union(set_tree234(T)::in, set_tree234(T)::in,
      set_tree234(T)::out) is det.
-:- func set_tree234.union(set_tree234(T), set_tree234(T)) = set_tree234(T).

      % `set_tree234.union_list(A, B)' is true iff `B' is the union of
      % all the sets in `A'
      %
+:- func set_tree234.union_list(list(set_tree234(T))) = set_tree234(T).
  :- pred set_tree234.union_list(list(set_tree234(T))::in, set_tree234(T)::out)
      is det.
-:- func set_tree234.union_list(list(set_tree234(T))) = set_tree234(T).

      % `set_tree234.power_union(A) = B' is true iff `B' is the union of
      % all the sets in `A'
      %
+:- func set_tree234.power_union(set_tree234(set_tree234(T))) = set_tree234(T).
  :- pred set_tree234.power_union(set_tree234(set_tree234(T))::in,
      set_tree234(T)::out) is det.
-:- func set_tree234.power_union(set_tree234(set_tree234(T))) = set_tree234(T).

      % `set_tree234.intersect(SetA, SetB) = Set' is true iff `Set' is the
      % intersection of `SetA' and `SetB'.
      %
+:- func set_tree234.intersect(set_tree234(T), set_tree234(T)) = set_tree234(T).
  :- pred set_tree234.intersect(set_tree234(T)::in, set_tree234(T)::in,
      set_tree234(T)::out) is det.
-:- func set_tree234.intersect(set_tree234(T), set_tree234(T))
-    = set_tree234(T).

      % `set_tree234.power_intersect(A, B)' is true iff `B' is the
      % intersection of all the sets in `A'.
@@ -187,19 +186,19 @@
      % set containing all the elements of `SetA' except those that
      % occur in `SetB'.
      %
-:- pred set_tree234.difference(set_tree234(T)::in, set_tree234(T)::in,
-    set_tree234(T)::out) is det.
  :- func set_tree234.difference(set_tree234(T), set_tree234(T))
      = set_tree234(T).
+:- pred set_tree234.difference(set_tree234(T)::in, set_tree234(T)::in,
+    set_tree234(T)::out) is det.

      % `set_tree234.count(Set, Count)' is true iff `Set' has
      % `Count' elements.
      %
  :- func set_tree234.count(set_tree234(T)) = int.

+:- func set_tree234.map(func(T1) = T2, set_tree234(T1)) = set_tree234(T2).
  :- pred set_tree234.map(pred(T1, T2)::in(pred(in, out) is det),
      set_tree234(T1)::in, set_tree234(T2)::out) is det.
-:- func set_tree234.map(func(T1) = T2, set_tree234(T1)) = set_tree234(T2).

  :- pred set_tree234.filter_map(pred(T1, T2)::in(pred(in, out) is semidet),
      set_tree234(T1)::in, set_tree234(T2)::out) is det.
@@ -208,13 +207,89 @@
      = set_tree234(T2).
  :- mode set_tree234.filter_map(func(in) = out is semidet, in) = out is det.

-:- pred set_tree234.fold(pred(T1, T2, T2)::in(pred(in, in, out) is det),
-    set_tree234(T1)::in, T2::in, T2::out) is det.
  :- func set_tree234.fold(func(T1, T2) = T2, set_tree234(T1), T2) = T2.
+:- pred set_tree234.fold(pred(T1, T2, T2), set_tree234(T1), T2, T2).
+:- mode set_tree234.fold(pred(in, in, out) is det, in, in, out) is det.
+:- mode set_tree234.fold(pred(in, mdi, muo) is det, in, mdi, muo) is det.
+:- mode set_tree234.fold(pred(in, di, uo) is det, in, di, uo) is det.
+:- mode set_tree234.fold(pred(in, in, out) is semidet, in, in, out)
+    is semidet.
+:- mode set_tree234.fold(pred(in, mdi, muo) is semidet, in, mdi, muo)
+    is semidet.
+:- mode set_tree234.fold(pred(in, di, uo) is semidet, in, di, uo)
+    is semidet.

-:- pred set_tree234.fold2(
-    pred(T1, T2, T2, T3, T3)::in(pred(in, in, out, in, out) is det),
-    set_tree234(T1)::in, T2::in, T2::out, T3::in, T3::out) is det.
+:- pred set_tree234.fold2(pred(T1, T2, T2, T3, T3), set_tree234(T1),
+    T2, T2, T3, T3).
+:- mode set_tree234.fold2(pred(in, in, out, in, out) is det, in,
+    in, out, in, out) is det.
+:- mode set_tree234.fold2(pred(in, in, out, mdi, muo) is det, in,
+    in, out, mdi, muo) is det.
+:- mode set_tree234.fold2(pred(in, in, out, di, uo) is det, in,
+    in, out, di, uo) is det.
+:- mode set_tree234.fold2(pred(in, in, out, in, out) is semidet, in,
+    in, out, in, out) is semidet.
+:- mode set_tree234.fold2(pred(in, in, out, mdi, muo) is semidet, in,
+    in, out, mdi, muo) is semidet.
+:- mode set_tree234.fold2(pred(in, in, out, di, uo) is semidet, in,
+    in, out, di, uo) is semidet.
+
+:- pred set_tree234.fold3(
+    pred(T1, T2, T2, T3, T3, T4, T4), set_tree234(T1),
+    T2, T2, T3, T3, T4, T4).
+:- mode set_tree234.fold3(pred(in, in, out, in, out, in, out) is det, in,
+    in, out, in, out, in, out) is det.
+:- mode set_tree234.fold3(pred(in, in, out, in, out, mdi, muo) is det, in,
+    in, out, in, out, mdi, muo) is det.
+:- mode set_tree234.fold3(pred(in, in, out, in, out, di, uo) is det, in,
+    in, out, in, out, di, uo) is det.
+:- mode set_tree234.fold3(pred(in, in, out, in, out, in, out) is semidet, in,
+    in, out, in, out, in, out) is semidet.
+:- mode set_tree234.fold3(pred(in, in, out, in, out, mdi, muo) is semidet, in,
+    in, out, in, out, mdi, muo) is semidet.
+:- mode set_tree234.fold3(pred(in, in, out, in, out, di, uo) is semidet, in,
+    in, out, in, out, di, uo) is semidet.
+
+:- pred set_tree234.fold4(
+    pred(T1, T2, T2, T3, T3, T4, T4, T5, T5), set_tree234(T1),
+    T2, T2, T3, T3, T4, T4, T5, T5).
+:- mode set_tree234.fold4(pred(in, in, out, in, out, in, out, in, out) is det,
+    in, in, out, in, out, in, out, in, out) is det.
+:- mode set_tree234.fold4(pred(in, in, out, in, out, in, out, mdi, muo) is det,
+    in, in, out, in, out, in, out, mdi, muo) is det.
+:- mode set_tree234.fold4(pred(in, in, out, in, out, in, out, di, uo) is det,
+    in, in, out, in, out, in, out, di, uo) is det.
+:- mode set_tree234.fold4(
+    pred(in, in, out, in, out, in, out, in, out) is semidet,
+    in, in, out, in, out, in, out, in, out) is semidet.
+:- mode set_tree234.fold4(
+    pred(in, in, out, in, out, in, out, mdi, muo) is semidet,
+    in, in, out, in, out, in, out, mdi, muo) is semidet.
+:- mode set_tree234.fold4(
+    pred(in, in, out, in, out, in, out, di, uo) is semidet,
+    in, in, out, in, out, in, out, di, uo) is semidet.
+
+:- pred set_tree234.fold5(
+    pred(T1, T2, T2, T3, T3, T4, T4, T5, T5, T6, T6),
+    set_tree234(T1), T2, T2, T3, T3, T4, T4, T5, T5, T6, T6).
+:- mode set_tree234.fold5(
+    pred(in, in, out, in, out, in, out, in, out, in, out) is det,
+    in, in, out, in, out, in, out, in, out, in, out) is det.
+:- mode set_tree234.fold5(
+    pred(in, in, out, in, out, in, out, in, out, mdi, muo) is det,
+    in, in, out, in, out, in, out, in, out, mdi, muo) is det.
+:- mode set_tree234.fold5(
+    pred(in, in, out, in, out, in, out, in, out, di, uo) is det,
+    in, in, out, in, out, in, out, in, out, di, uo) is det.
+:- mode set_tree234.fold5(
+    pred(in, in, out, in, out, in, out, in, out, in, out) is semidet,
+    in, in, out, in, out, in, out, in, out, in, out) is semidet.
+:- mode set_tree234.fold5(
+    pred(in, in, out, in, out, in, out, in, out, mdi, muo) is semidet,
+    in, in, out, in, out, in, out, in, out, mdi, muo) is semidet.
+:- mode set_tree234.fold5(
+    pred(in, in, out, in, out, in, out, in, out, di, uo) is semidet,
+    in, in, out, in, out, in, out, in, out, di, uo) is semidet.

      % set_tree234.divide(Pred, Set, TruePart, FalsePart):
      % TruePart consists of those elements of Set for which Pred succeeds;
@@ -1948,6 +2023,67 @@
      Pred(E2, !A, !B),
      set_tree234.fold2(Pred, T3, !A, !B).

+set_tree234.fold3(_Pred, empty, !A, !B, !C).
+set_tree234.fold3(Pred, two(E, T0, T1), !A, !B, !C) :-
+    set_tree234.fold3(Pred, T0, !A, !B, !C),
+    Pred(E, !A, !B, !C),
+    set_tree234.fold3(Pred, T1, !A, !B, !C).
+set_tree234.fold3(Pred, three(E0, E1, T0, T1, T2), !A, !B, !C) :-
+    set_tree234.fold3(Pred, T0, !A, !B, !C),
+    Pred(E0, !A, !B, !C),
+    set_tree234.fold3(Pred, T1, !A, !B, !C),
+    Pred(E1, !A, !B, !C),
+    set_tree234.fold3(Pred, T2, !A, !B, !C).
+set_tree234.fold3(Pred, four(E0, E1, E2, T0, T1, T2, T3), !A, !B, !C) :-
+    set_tree234.fold3(Pred, T0, !A, !B, !C),
+    Pred(E0, !A, !B, !C),
+    set_tree234.fold3(Pred, T1, !A, !B, !C),
+    Pred(E1, !A, !B, !C),
+    set_tree234.fold3(Pred, T2, !A, !B, !C),
+    Pred(E2, !A, !B, !C),
+    set_tree234.fold3(Pred, T3, !A, !B, !C).
+
+set_tree234.fold4(_Pred, empty, !A, !B, !C, !D).
+set_tree234.fold4(Pred, two(E, T0, T1), !A, !B, !C, !D) :-
+    set_tree234.fold4(Pred, T0, !A, !B, !C, !D),
+    Pred(E, !A, !B, !C, !D),
+    set_tree234.fold4(Pred, T1, !A, !B, !C, !D).
+set_tree234.fold4(Pred, three(E0, E1, T0, T1, T2), !A, !B, !C, !D) :-
+    set_tree234.fold4(Pred, T0, !A, !B, !C, !D),
+    Pred(E0, !A, !B, !C, !D),
+    set_tree234.fold4(Pred, T1, !A, !B, !C, !D),
+    Pred(E1, !A, !B, !C, !D),
+    set_tree234.fold4(Pred, T2, !A, !B, !C, !D).
+set_tree234.fold4(Pred, four(E0, E1, E2, T0, T1, T2, T3), !A, !B, !C, !D) :-
+    set_tree234.fold4(Pred, T0, !A, !B, !C, !D),
+    Pred(E0, !A, !B, !C, !D),
+    set_tree234.fold4(Pred, T1, !A, !B, !C, !D),
+    Pred(E1, !A, !B, !C, !D),
+    set_tree234.fold4(Pred, T2, !A, !B, !C, !D),
+    Pred(E2, !A, !B, !C, !D),
+    set_tree234.fold4(Pred, T3, !A, !B, !C, !D).
+
+set_tree234.fold5(_Pred, empty, !A, !B, !C, !D, !E).
+set_tree234.fold5(Pred, two(E, T0, T1), !A, !B, !C, !D, !E) :-
+    set_tree234.fold5(Pred, T0, !A, !B, !C, !D, !E),
+    Pred(E, !A, !B, !C, !D, !E),
+    set_tree234.fold5(Pred, T1, !A, !B, !C, !D, !E).
+set_tree234.fold5(Pred, three(E0, E1, T0, T1, T2), !A, !B, !C, !D, !E) :-
+    set_tree234.fold5(Pred, T0, !A, !B, !C, !D, !E),
+    Pred(E0, !A, !B, !C, !D, !E),
+    set_tree234.fold5(Pred, T1, !A, !B, !C, !D, !E),
+    Pred(E1, !A, !B, !C, !D, !E),
+    set_tree234.fold5(Pred, T2, !A, !B, !C, !D, !E).
+set_tree234.fold5(Pred, four(E0, E1, E2, T0, T1, T2, T3), !A, !B, !C, !D,
+        !E) :-
+    set_tree234.fold5(Pred, T0, !A, !B, !C, !D, !E),
+    Pred(E0, !A, !B, !C, !D, !E),
+    set_tree234.fold5(Pred, T1, !A, !B, !C, !D, !E),
+    Pred(E1, !A, !B, !C, !D, !E),
+    set_tree234.fold5(Pred, T2, !A, !B, !C, !D, !E),
+    Pred(E2, !A, !B, !C, !D, !E),
+    set_tree234.fold5(Pred, T3, !A, !B, !C, !D, !E).
+
  %------------------------------------------------------------------------------%

  set_tree234.map(Pred, SetA, SetB) :-
Index: library/set_unordlist.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/set_unordlist.m,v
retrieving revision 1.29
diff -u -r1.29 set_unordlist.m
--- library/set_unordlist.m	8 Nov 2010 03:43:43 -0000	1.29
+++ library/set_unordlist.m	8 Nov 2010 04:35:01 -0000
@@ -235,6 +235,89 @@
  :- mode set_unordlist.filter_map(func(in) = out is semidet, in) = out is det.

  :- func set_unordlist.fold(func(T1, T2) = T2, set_unordlist(T1), T2) = T2.
+:- pred set_unordlist.fold(pred(T1, T2, T2), set_unordlist(T1), T2, T2).
+:- mode set_unordlist.fold(pred(in, in, out) is det, in, in, out) is det.
+:- mode set_unordlist.fold(pred(in, mdi, muo) is det, in, mdi, muo) is det.
+:- mode set_unordlist.fold(pred(in, di, uo) is det, in, di, uo) is det.
+:- mode set_unordlist.fold(pred(in, in, out) is semidet, in, in, out)
+    is semidet.
+:- mode set_unordlist.fold(pred(in, mdi, muo) is semidet, in, mdi, muo)
+    is semidet.
+:- mode set_unordlist.fold(pred(in, di, uo) is semidet, in, di, uo)
+    is semidet.
+
+:- pred set_unordlist.fold2(pred(T1, T2, T2, T3, T3), set_unordlist(T1),
+    T2, T2, T3, T3).
+:- mode set_unordlist.fold2(pred(in, in, out, in, out) is det, in,
+    in, out, in, out) is det.
+:- mode set_unordlist.fold2(pred(in, in, out, mdi, muo) is det, in,
+    in, out, mdi, muo) is det.
+:- mode set_unordlist.fold2(pred(in, in, out, di, uo) is det, in,
+    in, out, di, uo) is det.
+:- mode set_unordlist.fold2(pred(in, in, out, in, out) is semidet, in,
+    in, out, in, out) is semidet.
+:- mode set_unordlist.fold2(pred(in, in, out, mdi, muo) is semidet, in,
+    in, out, mdi, muo) is semidet.
+:- mode set_unordlist.fold2(pred(in, in, out, di, uo) is semidet, in,
+    in, out, di, uo) is semidet.
+
+:- pred set_unordlist.fold3(pred(T1, T2, T2, T3, T3, T4, T4),
+    set_unordlist(T1), T2, T2, T3, T3, T4, T4).
+:- mode set_unordlist.fold3(pred(in, in, out, in, out, in, out) is det, in,
+    in, out, in, out, in, out) is det.
+:- mode set_unordlist.fold3(pred(in, in, out, in, out, mdi, muo) is det, in,
+    in, out, in, out, mdi, muo) is det.
+:- mode set_unordlist.fold3(pred(in, in, out, in, out, di, uo) is det, in,
+    in, out, in, out, di, uo) is det.
+:- mode set_unordlist.fold3(pred(in, in, out, in, out, in, out) is semidet, in,
+    in, out, in, out, in, out) is semidet.
+:- mode set_unordlist.fold3(pred(in, in, out, in, out, mdi, muo) is semidet, in,
+    in, out, in, out, mdi, muo) is semidet.
+:- mode set_unordlist.fold3(pred(in, in, out, in, out, di, uo) is semidet, in,
+    in, out, in, out, di, uo) is semidet.
+
+:- pred set_unordlist.fold4(pred(T1, T2, T2, T3, T3, T4, T4, T5, T5),
+    set_unordlist(T1), T2, T2, T3, T3, T4, T4, T5, T5).
+:- mode set_unordlist.fold4(
+    pred(in, in, out, in, out, in, out, in, out) is det, in,
+    in, out, in, out, in, out, in, out) is det.
+:- mode set_unordlist.fold4(
+    pred(in, in, out, in, out, in, out, mdi, muo) is det, in,
+    in, out, in, out, in, out, mdi, muo) is det.
+:- mode set_unordlist.fold4(
+    pred(in, in, out, in, out, in, out, di, uo) is det, in,
+    in, out, in, out, in, out, di, uo) is det.
+:- mode set_unordlist.fold4(
+    pred(in, in, out, in, out, in, out, in, out) is semidet, in,
+    in, out, in, out, in, out, in, out) is semidet.
+:- mode set_unordlist.fold4(
+    pred(in, in, out, in, out, in, out, mdi, muo) is semidet, in,
+    in, out, in, out, in, out, mdi, muo) is semidet.
+:- mode set_unordlist.fold4(
+    pred(in, in, out, in, out, in, out, di, uo) is semidet, in,
+    in, out, in, out, in, out, di, uo) is semidet.
+
+:- pred set_unordlist.fold5(
+    pred(T1, T2, T2, T3, T3, T4, T4, T5, T5, T6, T6),
+    set_unordlist(T1), T2, T2, T3, T3, T4, T4, T5, T5, T6, T6).
+:- mode set_unordlist.fold5(
+    pred(in, in, out, in, out, in, out, in, out, in, out) is det, in,
+    in, out, in, out, in, out, in, out, in, out) is det.
+:- mode set_unordlist.fold5(
+    pred(in, in, out, in, out, in, out, in, out, mdi, muo) is det, in,
+    in, out, in, out, in, out, in, out, mdi, muo) is det.
+:- mode set_unordlist.fold5(
+    pred(in, in, out, in, out, in, out, in, out, di, uo) is det, in,
+    in, out, in, out, in, out, in, out, di, uo) is det.
+:- mode set_unordlist.fold5(
+    pred(in, in, out, in, out, in, out, in, out, in, out) is semidet, in,
+    in, out, in, out, in, out, in, out, in, out) is semidet.
+:- mode set_unordlist.fold5(
+    pred(in, in, out, in, out, in, out, in, out, mdi, muo) is semidet, in,
+    in, out, in, out, in, out, in, out, mdi, muo) is semidet.
+:- mode set_unordlist.fold5(
+    pred(in, in, out, in, out, in, out, in, out, di, uo) is semidet, in,
+    in, out, in, out, in, out, in, out, di, uo) is semidet.

      % set_unordlist.divide(Pred, Set, TruePart, FalsePart):
      % TruePart consists of those elements of Set for which Pred succeeds;
@@ -383,6 +466,26 @@
      set_unordlist.difference_2(Es, B, C).

  %-----------------------------------------------------------------------------%
+
+set_unordlist.fold(F, S, A) = B :-
+    B = list.foldl(F, set_unordlist.to_sorted_list(S), A).
+
+set_unordlist.fold(P, S, !A) :-
+    list.foldl(P, set_unordlist.to_sorted_list(S), !A).
+
+set_unordlist.fold2(P, S, !A, !B) :-
+    list.foldl2(P, set_unordlist.to_sorted_list(S), !A, !B).
+
+set_unordlist.fold3(P, S, !A, !B, !C) :-
+    list.foldl3(P, set_unordlist.to_sorted_list(S), !A, !B, !C).
+
+set_unordlist.fold4(P, S, !A, !B, !C, !D) :-
+    list.foldl4(P, set_unordlist.to_sorted_list(S), !A, !B, !C, !D).
+
+set_unordlist.fold5(P, S, !A, !B, !C, !D, !E) :-
+    list.foldl5(P, set_unordlist.to_sorted_list(S), !A, !B, !C, !D, !E).
+
+%-----------------------------------------------------------------------------%
  %-----------------------------------------------------------------------------%
  % Ralph Becket <rwab1 at cam.sri.com> 24/04/99
  %   Function forms added.
@@ -437,9 +540,6 @@
      S2 = set_unordlist.list_to_set(list.filter_map(PF,
          set_unordlist.to_sorted_list(S1))).

-set_unordlist.fold(F, S, A) = B :-
-    B = list.foldl(F, set_unordlist.to_sorted_list(S), A).
-
  set_unordlist.divide(Pred, Set, RevTruePart, RevFalsePart) :-
      set_unordlist.divide_2(Pred, Set, [], RevTruePart, [], RevFalsePart).

@@ -456,3 +556,7 @@
          !:RevFalse = [H | !.RevFalse]
      ),
      set_unordlist.divide_2(Pred, T, !RevTrue, !RevFalse).
+
+%-----------------------------------------------------------------------------%
+:- end_module set_unordlist.
+%-----------------------------------------------------------------------------%

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