[m-rev.] for review: break up std_util (part 2)

Julien Fischer juliensf at cs.mu.OZ.AU
Wed Mar 29 16:22:24 AEDT 2006


This is the second part of the change to break up std_util.  It will
almost certainly break lots of existing code in various trivial ways.
(For the 0.13 release we'll probably add some stuff back to std_util in
order to make the transition a bit smoother.)  I'll post updates to the
NEWS file and other documentation as a separate diff.

Julien.

Estimated hours taken: 18
Branches: main

Move the univ, maybe, pair and unit types from std_util into their own
modules.  std_util still contains the general purpose higher-order programming
constructs.

library/std_util.m:
	Move univ, maybe, pair and unit (plus any other related types
	and procedures) into their own modules.

library/maybe.m:
	New module.  This contains the maybe and maybe_error types and
	the associated procedures.

library/pair.m:
	New module.  This contains the pair type and associated procedures.

library/unit.m:
	New module. This contains the types unit/0 and unit/1.

library/univ.m:
	New module. This contains the univ type and associated procedures.

library/library.m:
	Add the new modules.

library/private_builtin.m:
	Update the declaration of the type_ctor_info struct for univ.

runtime/mercury.h:
	Update the declaration for the type_ctor_info struct for univ.

runtime/mercury_mcpp.h:
runtime/mercury_hlc_types.h:
	Update the definition of MR_Univ.

runtime/mercury_init.h:
	Fix a comment: ML_type_name is now exported from type_desc.m.

compiler/mlds_to_il.m:
	Update the the name of the module that defines univs (which are
	handled specially by the il code generator.)

library/*.m:
compiler/*.m:
browser/*.m:
mdbcomp/*.m:
profiler/*.m:
deep_profiler/*.m:
	Conform to the above changes.  Import the new modules where they
	are needed; don't import std_util where it isn't needed.

	Fix formatting in lots of modules.  Delete duplicate module
	imports.

tests/*:
	Update the test suite to confrom to the above changes.

The following diff is just of the runtime and library directories (the
interesting parts of this change).  The complete diff is available at
~juliensf/tmp/STD_UTIL_DIFF)

Index: runtime/mercury.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury.h,v
retrieving revision 1.72
diff -u -r1.72 mercury.h
--- runtime/mercury.h	24 Feb 2006 07:11:19 -0000	1.72
+++ runtime/mercury.h	28 Mar 2006 05:35:08 -0000
@@ -135,7 +135,7 @@
 MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
 	mercury__array__array__type_ctor_info_array_1);
 MR_DECLARE_TYPE_CTOR_INFO_STRUCT(
-	mercury__std_util__std_util__type_ctor_info_univ_0);
+	mercury__univ__univ__type_ctor_info_univ_0);

 /*
 ** When generating code which passes an io__state or a store__store
Index: runtime/mercury_hlc_types.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_hlc_types.h,v
retrieving revision 1.5
diff -u -r1.5 mercury_hlc_types.h
--- runtime/mercury_hlc_types.h	8 Dec 2005 06:14:36 -0000	1.5
+++ runtime/mercury_hlc_types.h	28 Mar 2006 05:35:24 -0000
@@ -62,7 +62,7 @@
   typedef MR_ClosurePtr MR_Pred;
   typedef MR_ClosurePtr MR_Func;
   typedef struct mercury__array__array_1_s * MR_Array;
-  typedef struct mercury__std_util__univ_0_s * MR_Univ;
+  typedef struct mercury__univ__univ_0_s * MR_Univ;
   typedef struct mercury__type_desc__type_desc_0_s * MR_Type_Desc;
   typedef struct mercury__type_desc__pseudo_type_desc_0_s * MR_Pseudo_Type_Desc;
   typedef struct mercury__type_desc__type_ctor_desc_0_s * MR_Type_Ctor_Desc;
Index: runtime/mercury_init.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_init.h,v
retrieving revision 1.47
diff -u -r1.47 mercury_init.h
--- runtime/mercury_init.h	19 Sep 2005 07:26:33 -0000	1.47
+++ runtime/mercury_init.h	28 Mar 2006 05:37:01 -0000
@@ -153,7 +153,7 @@
 extern	void	MR_trace_init_external(void);
 extern	void	MR_trace_final_external(void);

-/* in library/std_util.m  */
+/* in library/type_desc.m  */
 extern	MR_String	ML_type_name(MR_Word);

 /* in runtime/mercury_trace_base.c */
Index: runtime/mercury_mcpp.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_mcpp.h,v
retrieving revision 1.32
diff -u -r1.32 mercury_mcpp.h
--- runtime/mercury_mcpp.h	5 Oct 2005 06:34:20 -0000	1.32
+++ runtime/mercury_mcpp.h	28 Mar 2006 05:36:30 -0000
@@ -50,7 +50,7 @@
   typedef __gc public class mercury::private_builtin::type_info_1* MR_TypeInfo;
   typedef __gc public class mercury::rtti_implementation::type_info_0* MR_TypeInfo_0;
   typedef __gc public class mercury::builtin::comparison_result_0 *MR_ComparisonResult;
-  typedef __gc public class mercury::std_util::univ_0 *MR_Univ;
+  typedef __gc public class mercury::univ::univ_0 *MR_Univ;
 #else
 */
   typedef __gc public class System::Object * MR_TypeInfo[];
Index: library/array.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/array.m,v
retrieving revision 1.143
diff -u -r1.143 array.m
--- library/array.m	7 Mar 2006 22:23:41 -0000	1.143
+++ library/array.m	23 Mar 2006 05:06:16 -0000
@@ -62,8 +62,8 @@
 :- interface.

 :- import_module list.
+:- import_module maybe.
 :- import_module random.
-:- import_module std_util.

 :- type array(T).

Index: library/array2d.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/array2d.m,v
retrieving revision 1.5
diff -u -r1.5 array2d.m
--- library/array2d.m	17 Oct 2005 11:35:16 -0000	1.5
+++ library/array2d.m	28 Mar 2006 04:36:55 -0000
@@ -5,23 +5,26 @@
 % 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.
 %-----------------------------------------------------------------------------%
-% Ralph Becket <rafe at cs.mu.oz.au>
-% Wed Jan 15 15:17:11 EST 2003
-%
+
+% File: array2d.m.
+% Author: Ralph Becket <rafe at cs.mu.oz.au>.
+% Stability: medium-low.
+
 % Two-dimensional rectangular (i.e. not ragged) array ADT.
 %
 % XXX The same caveats re: uniqueness of arrays apply to array2ds.
-%
+
 %-----------------------------------------------------------------------------%

 :- module array2d.
-
 :- interface.

 :- import_module array.
 :- import_module int.
 :- import_module list.

+%-----------------------------------------------------------------------------%
+
     % A array2d is a two-dimensional array stored in row-major order
     % (that is, the elements of the first row in left-to-right
     % order, followed by the elements of the second row and so forth.)
@@ -124,7 +127,6 @@

 :- import_module array.
 :- import_module require.
-:- import_module std_util.

     % array2d(Rows, Cols, Array)
     %
Index: library/assoc_list.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/assoc_list.m,v
retrieving revision 1.20
diff -u -r1.20 assoc_list.m
--- library/assoc_list.m	22 Mar 2006 02:56:16 -0000	1.20
+++ library/assoc_list.m	23 Mar 2006 06:20:42 -0000
@@ -17,11 +17,10 @@
 %-----------------------------------------------------------------------------%

 :- module assoc_list.
-
 :- interface.

 :- import_module list.
-:- import_module std_util.
+:- import_module pair.

 %-----------------------------------------------------------------------------%

Index: library/bag.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/bag.m,v
retrieving revision 1.28
diff -u -r1.28 bag.m
--- library/bag.m	7 Mar 2006 22:23:41 -0000	1.28
+++ library/bag.m	23 Mar 2006 06:26:21 -0000
@@ -5,17 +5,17 @@
 % 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: bag.m
-%   An implementation of multisets.
-% main author: conway, crs.
-% stability: medium
-%
+
+% File: bag.m.
+% Main authors: conway, crs.
+% Stability: medium.
+
+% An implementation of multisets.
+
 %---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%

 :- module bag.
-
 :- interface.

 :- import_module assoc_list.
@@ -223,8 +223,8 @@

 :- import_module int.
 :- import_module map.
+:- import_module pair.
 :- import_module require.
-:- import_module std_util.

 :- type bag(T)      ==  map(T, int).

Index: library/benchmarking.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/benchmarking.m,v
retrieving revision 1.67
diff -u -r1.67 benchmarking.m
--- library/benchmarking.m	7 Mar 2006 22:23:42 -0000	1.67
+++ library/benchmarking.m	28 Mar 2006 04:37:39 -0000
@@ -19,6 +19,8 @@
 :- module benchmarking.
 :- interface.

+:- import_module int.
+
     % `report_stats' is a non-logical procedure intended for use in profiling
     % the performance of a program. It has the side-effect of reporting
     % some memory and time usage statistics about the time period since
@@ -70,8 +72,7 @@

 :- implementation.

-:- import_module int.
-:- import_module std_util.
+%-----------------------------------------------------------------------------%

 :- pragma foreign_decl("C", "

@@ -82,7 +83,7 @@

 extern void ML_report_full_memory_stats(void);

-"). % end pragma foreign_decl
+").

 :- pragma foreign_proc("C",
     report_stats,
Index: library/bimap.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/bimap.m,v
retrieving revision 1.24
diff -u -r1.24 bimap.m
--- library/bimap.m	7 Mar 2006 22:23:42 -0000	1.24
+++ library/bimap.m	23 Mar 2006 06:26:43 -0000
@@ -299,8 +299,8 @@

 :- implementation.

+:- import_module pair.
 :- import_module require.
-:- import_module std_util.

 :- type bimap(K, V) --->    bimap(map(K, V), map(V, K)).

Index: library/bintree.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/bintree.m,v
retrieving revision 1.48
diff -u -r1.48 bintree.m
--- library/bintree.m	7 Mar 2006 22:23:42 -0000	1.48
+++ library/bintree.m	23 Mar 2006 06:27:05 -0000
@@ -132,8 +132,8 @@
 :- implementation.

 :- import_module int.
+:- import_module pair.
 :- import_module require.
-:- import_module std_util.
 :- import_module string.

 :- type bintree(K, V)
Index: library/bintree_set.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/bintree_set.m,v
retrieving revision 1.26
diff -u -r1.26 bintree_set.m
--- library/bintree_set.m	27 Mar 2006 01:01:03 -0000	1.26
+++ library/bintree_set.m	27 Mar 2006 01:09:34 -0000
@@ -187,7 +187,8 @@

 :- import_module assoc_list.
 :- import_module bintree.
-:- import_module std_util.
+:- import_module pair.
+:- import_module unit.

 :- type bintree_set(T)          ==      bintree(T, unit).

Index: library/builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/builtin.m,v
retrieving revision 1.118
diff -u -r1.118 builtin.m
--- library/builtin.m	24 Mar 2006 04:40:51 -0000	1.118
+++ library/builtin.m	28 Mar 2006 04:53:53 -0000
@@ -128,7 +128,7 @@
 % PREDICATES.
 %
 % Most of these probably ought to be moved to another
-% module in the standard library such as std_util.m.
+% module in the standard library such as util.m.

     % copy/2 makes a deep copy of a data structure.  The resulting copy is
     % a `unique' value, so you can use destructive update on it.
@@ -421,7 +421,6 @@
 :- import_module int.
 :- import_module list.
 :- import_module require.
-:- import_module std_util.
 :- import_module string.

 %-----------------------------------------------------------------------------%
Index: library/construct.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/construct.m,v
retrieving revision 1.27
diff -u -r1.27 construct.m
--- library/construct.m	22 Mar 2006 02:56:16 -0000	1.27
+++ library/construct.m	27 Mar 2006 06:57:54 -0000
@@ -14,14 +14,16 @@
 %-----------------------------------------------------------------------------%

 :- module construct.
-
 :- interface.

 :- import_module list.
-:- import_module std_util.
+:- import_module maybe.
+:- import_module univ.
 :- import_module type_desc.

-    % num_functors(TypeInfo)
+%-----------------------------------------------------------------------------%
+
+    % num_functors(TypeInfo).
     %
     % Returns the number of different functors for the top-level
     % type constructor of the type specified by TypeInfo, or -1
@@ -35,7 +37,7 @@
     %
 :- func num_functors(type_desc) = int.

-    % get_functor(Type, FunctorNumber, FunctorName, Arity, ArgTypes)
+    % get_functor(Type, FunctorNumber, FunctorName, Arity, ArgTypes).
     %
     % Binds FunctorName and Arity to the name and arity of functor number
     % FunctorNumber for the specified type, and binds ArgTypes to the
@@ -47,7 +49,7 @@
     list(pseudo_type_desc)::out) is semidet.

     % get_functor_with_names(Type, FunctorNumber, FunctorName, Arity, ArgTypes,
-    %   ArgNames)
+    %   ArgNames).
     %
     % Binds FunctorName and Arity to the name and arity of functor number
     % FunctorNumber for the specified type, ArgTypes to the type_descs
@@ -58,7 +60,7 @@
 :- pred get_functor_with_names(type_desc::in, int::in, string::out, int::out,
     list(pseudo_type_desc)::out, list(maybe(string))::out) is semidet.

-    % get_functor_ordinal(Type, I, Ordinal)
+    % get_functor_ordinal(Type, I, Ordinal).
     %
     % Returns Ordinal, where Ordinal is the position in declaration order
     % for the specified type of the function symbol that is in position I
@@ -67,7 +69,7 @@
     %
 :- pred get_functor_ordinal(type_desc::in, int::in, int::out) is semidet.

-    % construct(TypeInfo, I, Args) = Term
+    % construct(TypeInfo, I, Args) = Term.
     %
     % Returns a term of the type specified by TypeInfo whose functor
     % is functor number I of the type given by TypeInfo, and whose
@@ -80,7 +82,7 @@
 :- func construct(type_desc::in, int::in, list(univ)::in) = (univ::out)
     is semidet.

-    % construct_tuple(Args) = Term
+    % construct_tuple(Args) = Term.
     %
     % Returns a tuple whose arguments are given by Args.
     %
Index: library/deconstruct.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/deconstruct.m,v
retrieving revision 1.35
diff -u -r1.35 deconstruct.m
--- library/deconstruct.m	28 Mar 2006 08:07:27 -0000	1.35
+++ library/deconstruct.m	28 Mar 2006 13:58:12 -0000
@@ -14,11 +14,13 @@
 %-----------------------------------------------------------------------------%

 :- module deconstruct.
-
 :- interface.

 :- import_module list.
-:- import_module std_util.
+:- import_module maybe.
+:- import_module univ.
+
+%-----------------------------------------------------------------------------%

     % Values of type noncanon_handling are intended to control how
     % predicates that deconstruct terms behave when they find that
Index: library/dir.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/dir.m,v
retrieving revision 1.30
diff -u -r1.30 dir.m
--- library/dir.m	7 Mar 2006 22:23:43 -0000	1.30
+++ library/dir.m	29 Mar 2006 01:41:37 -0000
@@ -243,6 +243,9 @@
     %
 :- pred dir.use_windows_paths is semidet.

+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
 :- implementation.

 :- import_module char.
@@ -252,6 +255,8 @@
 :- import_module require.
 :- import_module std_util.

+%-----------------------------------------------------------------------------%
+
 dir.directory_separator = (if have_win32 then ('\\') else ('/')).

 :- pragma foreign_proc("C#",
Index: library/exception.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/exception.m,v
retrieving revision 1.106
diff -u -r1.106 exception.m
--- library/exception.m	24 Mar 2006 04:40:51 -0000	1.106
+++ library/exception.m	28 Mar 2006 04:53:25 -0000
@@ -19,13 +19,17 @@

 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
+
 :- module exception.
 :- interface.

 :- import_module io.
 :- import_module list.
-:- import_module std_util.
+:- import_module maybe.
 :- import_module store.
+:- import_module univ.
+
+%-----------------------------------------------------------------------------%

     % throw(Exception):
     %   Throw the specified exception.
@@ -242,9 +246,11 @@
 :- implementation.

 :- import_module require.
+:- import_module solutions.
 :- import_module string.
+:- import_module unit.

-:- use_module solutions.
+%-----------------------------------------------------------------------------%

 :- pred try(determinism,          pred(T),        exception_result(T)).
 :- mode try(in(bound(det)),   pred(out) is det,       out(cannot_fail))
@@ -1052,7 +1058,7 @@
     type_info_for_handler_pred.MR_ti_var_arity_arity = 2;
     type_info_for_handler_pred.MR_ti_var_arity_arg_typeinfos[0] =
         (MR_TypeInfo)
-        &mercury__std_util__std_util__type_ctor_info_univ_0;
+        &mercury__univ__univ__type_ctor_info_univ_0;
     type_info_for_handler_pred.MR_ti_var_arity_arg_typeinfos[1] =
         (MR_TypeInfo) agc_locals->type_info;
     /*
@@ -1529,7 +1535,7 @@
     #include ""mercury_deep_profiling_hand.h""

     MR_DECLARE_TYPE_CTOR_INFO_STRUCT( \
-            mercury_data_std_util__type_ctor_info_univ_0);
+            mercury_data_univ__type_ctor_info_univ_0);
 #endif
 ").

@@ -2356,7 +2362,7 @@
         MR_EXCEPTION_STRUCT->MR_excp_heap_zone->MR_zone_top);
     MR_save_transient_registers();
     exception = MR_deep_copy(exception,
-        (MR_TypeInfo) &mercury_data_std_util__type_ctor_info_univ_0,
+        (MR_TypeInfo) &mercury_data_univ__type_ctor_info_univ_0,
         MR_EXCEPTION_STRUCT->MR_excp_heap_ptr,
         MR_EXCEPTION_STRUCT->MR_excp_heap_zone->MR_zone_top);
     MR_restore_transient_registers();
@@ -2373,7 +2379,7 @@
         MR_ENGINE(MR_eng_solutions_heap_zone)->MR_zone_top);
     MR_save_transient_registers();
     exception = MR_deep_copy(exception,
-        (MR_TypeInfo) &mercury_data_std_util__type_ctor_info_univ_0,
+        (MR_TypeInfo) &mercury_data_univ__type_ctor_info_univ_0,
         saved_solns_heap_ptr,
         MR_ENGINE(MR_eng_solutions_heap_zone)->MR_zone_top);
     MR_restore_transient_registers();
Index: library/float.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/float.m,v
retrieving revision 1.67
diff -u -r1.67 float.m
--- library/float.m	7 Mar 2006 22:23:44 -0000	1.67
+++ library/float.m	29 Mar 2006 04:57:56 -0000
@@ -5,11 +5,11 @@
 % 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: float.m.
 % Main author: fjh.
 % Stability: medium.
-%
+
 % Floating point support.
 %
 % Note that implementations which support IEEE floating point
@@ -46,6 +46,7 @@
 % For example, the goal `1.0/9.0 = std_util.id(1.0)/9.0' may fail.

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

 :- module float.
 :- interface.
Index: library/getopt.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/getopt.m,v
retrieving revision 1.37
diff -u -r1.37 getopt.m
--- library/getopt.m	24 Mar 2006 04:40:52 -0000	1.37
+++ library/getopt.m	28 Mar 2006 04:38:01 -0000
@@ -85,8 +85,8 @@
 :- import_module char.
 :- import_module list.
 :- import_module map.
+:- import_module maybe.
 :- import_module set.
-:- import_module std_util.

 % getopt.process_options(OptionOps, Args, NonOptionArgs, Result)
 % getopt.process_options(OptionOps, Args, OptionArgs, NonOptionArgs, Result)
@@ -281,6 +281,7 @@

 :- implementation.

+:- import_module pair.
 :- import_module require.
 :- import_module string.
 :- import_module svset.
Index: library/getopt_io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/getopt_io.m,v
retrieving revision 1.6
diff -u -r1.6 getopt_io.m
--- library/getopt_io.m	24 Mar 2006 04:40:52 -0000	1.6
+++ library/getopt_io.m	28 Mar 2006 04:38:07 -0000
@@ -89,8 +89,8 @@
 :- import_module io.
 :- import_module list.
 :- import_module map.
+:- import_module maybe.
 :- import_module set.
-:- import_module std_util.

 % getopt_io.process_options(OptionOps, Args, NonOptionArgs, Result)
 % getopt_io.process_options(OptionOps, Args, OptionArgs, NonOptionArgs, Result)
@@ -286,6 +286,7 @@

 :- implementation.

+:- import_module pair.
 :- import_module require.
 :- import_module string.
 :- import_module svset.
Index: library/graph.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/graph.m,v
retrieving revision 1.27
diff -u -r1.27 graph.m
--- library/graph.m	24 Mar 2006 04:40:52 -0000	1.27
+++ library/graph.m	28 Mar 2006 04:38:20 -0000
@@ -23,7 +23,7 @@

 :- import_module list.
 :- import_module set.
-:- import_module std_util.
+:- import_module unit.

     % graph(Node, Arc) represents a directed graph with information of
     % type Node associated with each node, and information of type Arc
@@ -166,6 +166,7 @@
 :- mode graph.path(in, in, out, out) is nondet.

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

 :- implementation.

@@ -174,10 +175,11 @@
 :- import_module list.
 :- import_module map.
 :- import_module require.
-:- import_module std_util.

 :- use_module solutions.

+%------------------------------------------------------------------------------%
+
 :- type graph(N, A)
     --->    graph(
                 node_supply     :: counter,
Index: library/group.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/group.m,v
retrieving revision 1.24
diff -u -r1.24 group.m
--- library/group.m	7 Mar 2006 22:23:44 -0000	1.24
+++ library/group.m	28 Mar 2006 04:39:19 -0000
@@ -90,8 +90,8 @@
 :- import_module counter.
 :- import_module int.
 :- import_module map.
+:- import_module pair.
 :- import_module require.
-:- import_module std_util.

 :- type group(T)
     --->    group(
Index: library/hash_table.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/hash_table.m,v
retrieving revision 1.13
diff -u -r1.13 hash_table.m
--- library/hash_table.m	22 Mar 2006 02:56:16 -0000	1.13
+++ library/hash_table.m	27 Mar 2006 07:09:59 -0000
@@ -5,11 +5,11 @@
 % 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: hash_table.m
 % Main author: rafe
 % Stability: low
-%
+
 % Hash table implementation.
 %
 % This implementation uses double hashing and requires the user to
@@ -32,11 +32,11 @@
 % This means that care must be taken not to use an old version of a
 % destructively updated structure (such as a hash_table) since the
 % compiler will not currently detect such errors.
-%
+
+%-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%

 :- module hash_table.
-
 :- interface.

 :- import_module array.
@@ -47,6 +47,8 @@
 :- import_module int.
 :- import_module string.

+%-----------------------------------------------------------------------------%
+
 :- type hash_table(K, V).

     % XXX This is all fake until the compiler can handle nested unique modes.
@@ -203,6 +205,7 @@

 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
+
 :- implementation.

 :- import_module bool.
@@ -210,9 +213,12 @@
 :- import_module exception.
 :- import_module list.
 :- import_module math.
+:- import_module pair.
 :- import_module require.
-:- import_module std_util.
 :- import_module type_desc.
+:- import_module univ.
+
+%-----------------------------------------------------------------------------%

 :- type hash_table(K, V)
     --->    ht(
Index: library/injection.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/injection.m,v
retrieving revision 1.3
diff -u -r1.3 injection.m
--- library/injection.m	17 Oct 2005 11:35:17 -0000	1.3
+++ library/injection.m	28 Mar 2006 04:39:29 -0000
@@ -309,8 +309,8 @@

 :- implementation.

+:- import_module pair.
 :- import_module require.
-:- import_module std_util.
 :- import_module string.
 :- import_module svmap.

Index: library/int.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/int.m,v
retrieving revision 1.111
diff -u -r1.111 int.m
--- library/int.m	7 Mar 2006 22:23:44 -0000	1.111
+++ library/int.m	28 Mar 2006 04:22:28 -0000
@@ -381,7 +381,8 @@

 :- import_module exception.
 :- import_module math.
-:- import_module std_util.
+
+%-----------------------------------------------------------------------------%

 :- instance enum(int) where [
     to_int(X) = X,
Index: library/integer.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/integer.m,v
retrieving revision 1.21
diff -u -r1.21 integer.m
--- library/integer.m	7 Mar 2006 22:23:44 -0000	1.21
+++ library/integer.m	28 Mar 2006 04:39:10 -0000
@@ -5,12 +5,11 @@
 % 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: integer.m
-% main authors:
-% aet Mar 1998.
-% Dan Hazel <odin at svrc.uq.edu.au> Oct 1999.
-%
+
+% File: integer.m.
+% Main authors: aet, Dan Hazel <odin at svrc.uq.edu.au>.
+% Stability: high.
+
 % Implements an arbitrary precision integer type and basic
 % operations on it. (An arbitrary precision integer may have
 % any number of digits, unlike an int, which is limited to the
@@ -18,11 +17,11 @@
 %
 % NOTE: All operators behave as the equivalent operators on ints do.
 % This includes the division operators: / // rem div mod.
-%
+
+%-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%

 :- module integer.
-
 :- interface.

 :- import_module float.
@@ -105,7 +104,6 @@
 :- import_module int.
 :- import_module list.
 :- import_module require.
-:- import_module std_util.

 % Possible improvements:
 %
Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.344
diff -u -r1.344 io.m
--- library/io.m	22 Mar 2006 02:56:16 -0000	1.344
+++ library/io.m	27 Mar 2006 06:58:52 -0000
@@ -33,9 +33,10 @@
 :- import_module deconstruct.
 :- import_module list.
 :- import_module map.
-:- import_module std_util.
+:- import_module maybe.
 :- import_module string.
 :- import_module time.
+:- import_module univ.

 %-----------------------------------------------------------------------------%
 %
Index: library/library.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/library.m,v
retrieving revision 1.94
diff -u -r1.94 library.m
--- library/library.m	29 Mar 2006 01:35:18 -0000	1.94
+++ library/library.m	29 Mar 2006 01:41:30 -0000
@@ -11,11 +11,10 @@
 % It is used as a way for the Makefiles to know which library interface
 % files, objects, etc., need to be installed.
 %
-% ---------------------------------------------------------------------------%
-% ---------------------------------------------------------------------------%
+%----------------------------------------------------------------------------%
+%----------------------------------------------------------------------------%

 :- module library.
-
 :- interface.

 :- pred library.version(string::out) is det.
@@ -80,8 +79,10 @@
 :- import_module list.
 :- import_module map.
 :- import_module math.
+:- import_module maybe.
 :- import_module multi_map.
 :- import_module ops.
+:- import_module pair.
 :- import_module parser.
 :- import_module pprint.
 :- import_module pqueue.
@@ -121,6 +122,8 @@
 :- import_module time.
 :- import_module tree234.
 :- import_module type_desc.
+:- import_module univ.
+:- import_module unit.
 :- import_module varset.
 :- import_module version_array.
 :- import_module version_array2d.
@@ -217,9 +220,11 @@
 mercury_std_library_module("list").
 mercury_std_library_module("map").
 mercury_std_library_module("math").
+mercury_std_library_module("maybe").
 mercury_std_library_module("multi_map").
 mercury_std_library_module("mutvar").
 mercury_std_library_module("ops").
+mercury_std_library_module("pair").
 mercury_std_library_module("parser").
 mercury_std_library_module("pprint").
 mercury_std_library_module("pqueue").
@@ -264,6 +269,8 @@
 mercury_std_library_module("time").
 mercury_std_library_module("tree234").
 mercury_std_library_module("type_desc").
+mercury_std_library_module("univ").
+mercury_std_library_module("unit").
 % mercury_std_library_module("unsafe").
 mercury_std_library_module("varset").
 mercury_std_library_module("version_array").
Index: library/list.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/list.m,v
retrieving revision 1.146
diff -u -r1.146 list.m
--- library/list.m	7 Mar 2006 22:23:45 -0000	1.146
+++ library/list.m	28 Mar 2006 04:36:11 -0000
@@ -1165,7 +1165,6 @@

 :- import_module require.
 :- import_module set_tree234.
-:- import_module std_util.
 :- import_module string.

 %-----------------------------------------------------------------------------%
Index: library/map.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/map.m,v
retrieving revision 1.102
diff -u -r1.102 map.m
--- library/map.m	7 Mar 2006 22:23:45 -0000	1.102
+++ library/map.m	23 Mar 2006 06:22:27 -0000
@@ -519,8 +519,8 @@

 :- implementation.

+:- import_module pair.
 :- import_module require.
-:- import_module std_util.
 :- import_module string.
 :- import_module svmap.
 :- import_module svset.
Index: library/maybe.m
===================================================================
RCS file: library/maybe.m
diff -N library/maybe.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ library/maybe.m	23 Mar 2006 05:07:30 -0000
@@ -0,0 +1,113 @@
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%-----------------------------------------------------------------------------%
+% Copyright (C) 1994-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: maybe.m.
+% Main author: fjh.
+% Stability: high.
+
+% This module defines the "maybe" type.
+
+%-----------------------------------------------------------------------------%
+
+:- module maybe.
+:- interface.
+
+%-----------------------------------------------------------------------------%
+
+:- type maybe(T)
+	--->	no
+    ;       yes(T).
+
+:- inst maybe(I)
+    --->    no
+    ;       yes(I).
+
+:- type maybe_error
+    --->    ok
+    ;       error(string).
+
+:- type maybe_error(T)
+    --->    ok(T)
+    ;       error(string).
+
+:- inst maybe_error(I)
+    --->    ok(I)
+    ;       error(ground).
+
+    % map_maybe(P, yes(Value0), yes(Value)) :- P(Value, Value).
+    % map_maybe(_, no, no).
+    %
+:- pred map_maybe(pred(T, U), maybe(T), maybe(U)).
+:- mode map_maybe(pred(in, out) is det, in, out) is det.
+:- mode map_maybe(pred(in, out) is semidet, in, out) is semidet.
+:- mode map_maybe(pred(in, out) is multi, in, out) is multi.
+:- mode map_maybe(pred(in, out) is nondet, in, out) is nondet.
+
+    % map_maybe(_, no) = no.
+    % map_maybe(F, yes(Value)) = yes(F(Value)).
+    %
+:- func map_maybe(func(T) = U, maybe(T)) = maybe(U).
+
+    % fold_maybe(_, no, !Acc).
+    % fold_maybe(P, yes(Value), !Acc) :- P(Value, !Acc).
+    %
+:- pred fold_maybe(pred(T, U, U), maybe(T), U, U).
+:- mode fold_maybe(pred(in, in, out) is det, in, in, out) is det.
+:- mode fold_maybe(pred(in, in, out) is semidet, in, in, out) is semidet.
+:- mode fold_maybe(pred(in, di, uo) is det, in, di, uo) is det.
+
+    % fold_maybe(_, no, Acc) = Acc.
+    % fold_maybe(F, yes(Value), Acc0) = F(Acc0).
+    %
+:- func fold_maybe(func(T, U) = U, maybe(T), U) = U.
+
+    % map_fold_maybe(_, no, no, !Acc).
+    % map_fold_maybe(P, yes(Value0), yes(Value), !Acc) :-
+    %      P(Value, Value, !Acc).
+    %
+:- pred map_fold_maybe(pred(T, U, Acc, Acc), maybe(T), maybe(U), Acc, Acc).
+:- mode map_fold_maybe(pred(in, out, in, out) is det, in, out, in, out) is det.
+:- mode map_fold_maybe(pred(in, out, di, uo) is det, in, out, di, uo) is det.
+
+    % As above, but with two accumulators.
+    %
+:- pred map_fold2_maybe(pred(T, U, Acc1, Acc1, Acc2, Acc2),
+    maybe(T), maybe(U), Acc1, Acc1, Acc2, Acc2).
+:- mode map_fold2_maybe(pred(in, out, in, out, in, out) is det, in, out,
+    in, out, in, out) is det.
+:- mode map_fold2_maybe(pred(in, out, in, out, di, uo) is det,
+    in, out, in, out, di, uo) is det.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+map_maybe(_, no, no).
+map_maybe(P, yes(T0), yes(T)) :- P(T0, T).
+
+map_maybe(_, no) = no.
+map_maybe(F, yes(T)) = yes(F(T)).
+
+fold_maybe(_, no, !Acc).
+fold_maybe(P, yes(Value), !Acc) :- P(Value, !Acc).
+
+fold_maybe(_, no, Acc) = Acc.
+fold_maybe(F, yes(Value), Acc0) = F(Value, Acc0).
+
+map_fold_maybe(_, no, no, Acc, Acc).
+map_fold_maybe(P, yes(T0), yes(T), Acc0, Acc) :-
+    P(T0, T, Acc0, Acc).
+
+map_fold2_maybe(_, no, no, !A, !B).
+map_fold2_maybe(P, yes(T0), yes(T), !A, !B) :-
+    P(T0, T, !A, !B).
+
+%-----------------------------------------------------------------------------%
+:- end_module maybe.
+%-----------------------------------------------------------------------------%
Index: library/multi_map.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/multi_map.m,v
retrieving revision 1.21
diff -u -r1.21 multi_map.m
--- library/multi_map.m	13 Mar 2006 04:00:13 -0000	1.21
+++ library/multi_map.m	28 Mar 2006 04:35:51 -0000
@@ -5,11 +5,11 @@
 % 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: multi_map.m.
 % Main author: dylan.  Based on map.m, by fjh, conway.
 % Stability: low.
-%
+
 % This file provides the 'multi_map' ADT.
 % A map (also known as a dictionary or an associative array) is a collection
 % of (Key, Data) pairs which allows you to look up any Data item given the
@@ -17,7 +17,7 @@
 % between keys and data.
 %
 % This is implemented almost as a special case of map.m.
-%
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%

@@ -258,8 +258,8 @@
 :- implementation.

 :- import_module int.
+:- import_module pair.
 :- import_module require.
-:- import_module std_util.
 :- import_module string.

 %-----------------------------------------------------------------------------%
Index: library/pair.m
===================================================================
RCS file: library/pair.m
diff -N library/pair.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ library/pair.m	23 Mar 2006 06:16:07 -0000
@@ -0,0 +1,58 @@
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%-----------------------------------------------------------------------------%
+% Copyright (C) 1994-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: pair.m.
+% Main author: fjh.
+% Stability: high.
+
+% The "pair" type.  Useful for many purposes.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- module pair.
+:- interface.
+
+:- type pair(T1, T2)
+    --->    (T1 - T2).
+:- type pair(T) ==  pair(T, T).
+
+:- inst pair(I1, I2)
+    --->    (I1 - I2).
+:- inst pair(I) ==  pair(I, I).
+
+    % Return the first element of the pair.
+    %
+:- func fst(pair(X, Y)) = X.
+:- pred fst(pair(X, Y)::in, X::out) is det.
+
+    % Return the second element of the pair.
+    %
+:- func snd(pair(X, Y)) = Y.
+:- pred snd(pair(X, Y)::in, Y::out) is det.
+
+:- func pair(T1, T2) = pair(T1, T2).
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+fst(X - _Y) = X.
+fst(P, X) :-
+    X = fst(P).
+
+snd(_X - Y) = Y.
+snd(P, X) :-
+    X = snd(P).
+
+pair(X, Y) = X - Y.
+
+%-----------------------------------------------------------------------------%
+:- end_module pair.
+%-----------------------------------------------------------------------------%
Index: library/parser.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/parser.m,v
retrieving revision 1.50
diff -u -r1.50 parser.m
--- library/parser.m	7 Mar 2006 22:23:46 -0000	1.50
+++ library/parser.m	28 Mar 2006 04:35:36 -0000
@@ -5,11 +5,11 @@
 % 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: parser.m.
-% main author: fjh.
-% stability: high.
-%
+
+% File: parser.m.
+% Main author: fjh.
+% Stability: high.
+
 % This file exports the predicate read_term, which reads
 % a term from the current input stream.
 % The read_term_from_string predicates are the same as the
@@ -31,7 +31,8 @@
 % parser, made somewhat complicated by the need to handle operator
 % precedences.  It uses `lexer.get_token_list' to read a list of tokens.
 % It uses the routines in module `ops' to look up operator precedences.
-%
+
+%-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%

 :- module parser.
@@ -142,8 +143,8 @@
 :- import_module lexer.
 :- import_module list.
 :- import_module map.
+:- import_module maybe.
 :- import_module require.
-:- import_module std_util.
 :- import_module string.
 :- import_module term.
 :- import_module varset.
Index: library/pprint.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/pprint.m,v
retrieving revision 1.20
diff -u -r1.20 pprint.m
--- library/pprint.m	22 Mar 2006 02:56:17 -0000	1.20
+++ library/pprint.m	27 Mar 2006 07:11:33 -0000
@@ -5,12 +5,11 @@
 % 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: pprint.m
 % Main author: rafe
 % Stability: medium
-%
-%
+
 % ABOUT
 % -----
 %
@@ -147,11 +146,11 @@
 %   Look! Goodbye
 %   Look!    cruel
 %   Look!    world
-%
+
+%-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%

 :- module pprint.
-
 :- interface.

 :- import_module char.
@@ -159,8 +158,10 @@
 :- import_module int.
 :- import_module io.
 :- import_module list.
-:- import_module std_util.
 :- import_module string.
+:- import_module univ.
+
+%-----------------------------------------------------------------------------%

     % Clients must translate data structures into docs for
     % the pretty printer to display.
@@ -381,11 +382,14 @@
 :- import_module exception.
 :- import_module map.
 :- import_module ops.
+:- import_module pair.
 :- import_module robdd.
 :- import_module sparse_bitset.
 :- import_module term.
 :- import_module type_desc.

+%-----------------------------------------------------------------------------%
+
 :- type doc
     --->    'NIL'
     ;       'SEQ'(doc, doc)
Index: library/pqueue.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/pqueue.m,v
retrieving revision 1.21
diff -u -r1.21 pqueue.m
--- library/pqueue.m	7 Mar 2006 22:23:46 -0000	1.21
+++ library/pqueue.m	28 Mar 2006 04:35:11 -0000
@@ -5,11 +5,13 @@
 % 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 pqueue.m - implements a priority queue ADT.
-% main author: conway.
-% stability: high.
-%
+
+% File: pqueue.m.
+% Main author: conway.
+% Stability: high.
+
+% This module implements a priority queue ADT.
+%
 % A pqueue is a priority queue.  A priority queue holds a collection
 % of key-value pairs; the interface provides operations to create
 % an empty priority queue, to insert a key-value pair into a priority
@@ -18,16 +20,17 @@
 % Insertion/removal is not guaranteed to be "stable"; that is,
 % if you insert two values with the same key, the order in which
 % they will be removed is unspecified.
-%
+
 %---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%

 :- module pqueue.
-
 :- interface.

 :- import_module assoc_list.

+%---------------------------------------------------------------------------%
+
 :- type pqueue(K, V).

     % Create an empty priority queue.
@@ -71,7 +74,7 @@

 :- import_module int.
 :- import_module list.
-:- import_module std_util.
+:- import_module pair.

 :- type pqueue(K, V)
     --->    empty
Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.153
diff -u -r1.153 private_builtin.m
--- library/private_builtin.m	22 Mar 2006 02:56:17 -0000	1.153
+++ library/private_builtin.m	27 Mar 2006 23:56:55 -0000
@@ -113,9 +113,9 @@
 :- import_module int.
 :- import_module list.
 :- import_module require.
-:- import_module std_util.
 :- import_module string.
 :- import_module type_desc.
+:- import_module univ.

 :- pragma foreign_code("C#", "

@@ -967,7 +967,7 @@
 :- pred reclaim_heap_nondet_pragma_foreign_code is erroneous.

     % The following is a built-in reference type. It is used to define the
-    % types store.generic_ref/2, store.generic_mutvar/2, std_util.mutvar/1,
+    % types store.generic_ref/2, store.generic_mutvar/2, solutions.mutvar/1,
     % benchmarking.int_ref/0, etc.
 :- type ref(T).

@@ -1137,14 +1137,14 @@
 #include ""mercury_builtin_types.h""

 MR_DECLARE_TYPE_CTOR_INFO_STRUCT(MR_TYPE_CTOR_INFO_NAME(list, list, 1));
-MR_DECLARE_TYPE_CTOR_INFO_STRUCT(MR_TYPE_CTOR_INFO_NAME(std_util, univ, 0));
+MR_DECLARE_TYPE_CTOR_INFO_STRUCT(MR_TYPE_CTOR_INFO_NAME(univ, univ, 0));

 ").

 :- pragma foreign_code("C", "

 const MR_TypeCtorInfo ML_type_ctor_info_for_univ =
-    &MR_TYPE_CTOR_INFO_NAME(std_util, univ, 0);
+    &MR_TYPE_CTOR_INFO_NAME(univ, univ, 0);

 const MR_TypeCtorInfo ML_type_info_for_type_info =
     &MR_TYPE_CTOR_INFO_NAME(private_builtin, type_info, 0);
@@ -1158,7 +1158,7 @@

 const MR_FA_TypeInfo_Struct1 ML_type_info_for_list_of_univ = {
     &MR_TYPE_CTOR_INFO_NAME(list, list, 1),
-    { (MR_TypeInfo) &MR_TYPE_CTOR_INFO_NAME(std_util, univ, 0) }
+    { (MR_TypeInfo) &MR_TYPE_CTOR_INFO_NAME(univ, univ, 0) }
 };

 const MR_FA_TypeInfo_Struct1 ML_type_info_for_list_of_int = {
@@ -1259,7 +1259,7 @@

     % var/1 is intended to make it possible to write code that effectively
     % has different implementations for different modes (see type_to_univ
-    % in std_util.m as an example). It has to be impure to ensure that
+    % in univ.m as an example). It has to be impure to ensure that
     % reordering doesn't cause the wrong mode to be selected.
     %
 :- impure pred var(T).
Index: library/profiling_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/profiling_builtin.m,v
retrieving revision 1.16
diff -u -r1.16 profiling_builtin.m
--- library/profiling_builtin.m	7 Mar 2006 22:23:46 -0000	1.16
+++ library/profiling_builtin.m	28 Mar 2006 04:34:19 -0000
@@ -5,23 +5,25 @@
 % 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: profiling_builtin.m.
 % Authors: conway, zs.
 % Stability: low.
-%
+
 % This file is automatically imported into every module when deep profiling
 % is enabled. It contains support predicates used for deep profiling.
 % The tasks of the support predicates are described in some detail in
 % ``Engineering a profiler for a logic programming language'' by Thomas Conway
 % and Zoltan Somogyi.
-%
+
+%---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%

 :- module profiling_builtin.
-
 :- interface.

+%---------------------------------------------------------------------------%
+
 :- type proc_layout.
 :- type proc_dynamic.
 :- type call_site_dynamic.
@@ -1508,8 +1510,6 @@
 #undef MR_REC_DEPTH_BODY
 }").

-:- import_module std_util.
-
 % These versions are only used for back-ends for which there is no
     % matching foreign_proc version.

Index: library/prolog.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/prolog.m,v
retrieving revision 1.17
diff -u -r1.17 prolog.m
--- library/prolog.m	22 Mar 2006 02:56:18 -0000	1.17
+++ library/prolog.m	27 Mar 2006 07:12:03 -0000
@@ -12,11 +12,16 @@
 % of Mercury and Prolog.

 %-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
 :- module prolog.
 :- interface.

 :- import_module list.
-:- import_module std_util.
+:- import_module pair.
+:- import_module univ.
+
+%-----------------------------------------------------------------------------%

 % Prolog arithmetic operators.

@@ -69,6 +74,7 @@
 :- pred det_arg(int::in, T::in, univ::out) is det.

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

 :- implementation.

@@ -76,6 +82,8 @@
 :- import_module int.
 :- import_module require.

+%-----------------------------------------------------------------------------%
+
 % we use module qualifiers here to avoid
 % overriding the builtin Prolog versions

Index: library/queue.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/queue.m,v
retrieving revision 1.31
diff -u -r1.31 queue.m
--- library/queue.m	7 Mar 2006 22:23:47 -0000	1.31
+++ library/queue.m	28 Mar 2006 04:33:43 -0000
@@ -19,11 +19,14 @@
 % The put and get operations are amortized constant-time.

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

 :- module queue.
 :- interface.
 :- import_module list.

+%--------------------------------------------------------------------------%
+
 :- type queue(T).

     % `queue.init(Queue)' is true iff `Queue' is an empty queue.
@@ -121,7 +124,9 @@
 :- implementation.

 :- import_module int.
-:- import_module std_util.
+:- import_module pair.
+
+%--------------------------------------------------------------------------%

     % This implementation is in terms of a pair of lists. We impose the
     % extra constraint that the `off' list is empty if and only if the queue
Index: library/rbtree.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/rbtree.m,v
retrieving revision 1.23
diff -u -r1.23 rbtree.m
--- library/rbtree.m	7 Mar 2006 22:23:47 -0000	1.23
+++ library/rbtree.m	28 Mar 2006 04:23:06 -0000
@@ -5,11 +5,11 @@
 % 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.
 %-----------------------------------------------------------------------------%
-%
-% Red-black tree module.
+
+% File: rbtree.m.
 % Main author: petdr.
 % Stability: medium.
-%
+
 % Contains an implementation of red black trees.
 %
 % *** Exit conditions of main predicates ***
@@ -46,6 +46,8 @@
 :- import_module assoc_list.
 :- import_module list.

+%-----------------------------------------------------------------------------%
+
 :- type rbtree(Key, Value).

     % Initialise the data structure.
@@ -229,8 +231,11 @@

 :- import_module bool.
 :- import_module int.
+:- import_module maybe.
+:- import_module pair.
 :- import_module require.
-:- import_module std_util.
+
+%-----------------------------------------------------------------------------%

 :- type rbtree(K,V)
     --->    empty
Index: library/relation.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/relation.m,v
retrieving revision 1.39
diff -u -r1.39 relation.m
--- library/relation.m	7 Mar 2006 22:23:47 -0000	1.39
+++ library/relation.m	28 Mar 2006 04:33:20 -0000
@@ -18,7 +18,6 @@
 %------------------------------------------------------------------------------%

 :- module relation.
-
 :- interface.

 :- import_module assoc_list.
@@ -308,11 +307,13 @@
 :- import_module int.
 :- import_module list.
 :- import_module map.
+:- import_module pair.
 :- import_module queue.
 :- import_module require.
 :- import_module sparse_bitset.
 :- import_module stack.
-:- import_module std_util.
+
+%------------------------------------------------------------------------------%

 :- type relation_key
     --->    relation_key(int).
Index: library/require.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/require.m,v
retrieving revision 1.38
diff -u -r1.38 require.m
--- library/require.m	22 Mar 2006 02:56:18 -0000	1.38
+++ library/require.m	28 Mar 2006 04:31:54 -0000
@@ -67,10 +67,11 @@

 :- import_module exception.
 :- import_module list.
-:- import_module std_util.
 :- import_module string.
 :- import_module type_desc.

+%-----------------------------------------------------------------------------%
+
 require(Goal, Message) :-
     ( call(Goal) ->
         true
Index: library/robdd.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/robdd.m,v
retrieving revision 1.8
diff -u -r1.8 robdd.m
--- library/robdd.m	7 Mar 2006 22:23:47 -0000	1.8
+++ library/robdd.m	28 Mar 2006 04:31:41 -0000
@@ -7,8 +7,8 @@
 %---------------------------------------------------------------------------%

 % File: robdd.m.
-% Main author: dmo
-% Stability: low
+% Main author: dmo.
+% Stability: low.

 % This module contains a Mercury interface to Peter Schachte's C
 % implementation of Reduced Ordered Binary Decision Diagrams (ROBDDs).
@@ -51,7 +51,6 @@
 %-----------------------------------------------------------------------------%

 :- module robdd.
-
 :- interface.

 :- import_module io.
@@ -356,10 +355,10 @@
 :- import_module list.
 :- import_module map.
 :- import_module multi_map.
+:- import_module pair.
 :- import_module require.
 :- import_module set_bbbtree.
 :- import_module set_unordlist.
-:- import_module std_util.
 :- import_module string.

 % :- import_module unsafe.
Index: library/rtti_implementation.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/rtti_implementation.m,v
retrieving revision 1.65
diff -u -r1.65 rtti_implementation.m
--- library/rtti_implementation.m	24 Mar 2006 04:40:52 -0000	1.65
+++ library/rtti_implementation.m	27 Mar 2006 07:02:54 -0000
@@ -35,17 +35,19 @@
 % XXX Also, the existing Java code needs to be reviewed.
 %
 %-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- module rtti_implementation.
-
 :- interface.

 :- import_module deconstruct.
 :- import_module list.
+:- import_module univ.

-:- use_module std_util.
 :- use_module type_desc.

+%-----------------------------------------------------------------------------%
+
     % Our type_info and type_ctor_info implementations are both
     % abstract types.
 :- type type_info.
@@ -67,7 +69,7 @@
 :- pred type_ctor_name_and_arity(type_ctor_info::in,
         string::out, string::out, int::out) is det.

-:- pred deconstruct(T, noncanon_handling, string, int, list(std_util.univ)).
+:- pred deconstruct(T, noncanon_handling, string, int, list(univ)).
 :- mode deconstruct(in, in(do_not_allow), out, out, out) is det.
 :- mode deconstruct(in, in(canonicalize), out, out, out) is det.
 :- mode deconstruct(in, in(include_details_cc), out, out, out) is cc_multi.
@@ -99,14 +101,11 @@
 :- import_module array.
 :- import_module bool.
 :- import_module int.
+:- import_module maybe.
 :- import_module require.
 :- import_module string.
 :- import_module type_desc.

-    % Std_util has a lot of types and functions with the same names,
-    % so we prefer to keep the namespace separate.
-:- use_module std_util.
-
     % It is convenient to represent the type_ctor_rep as a Mercury
     % enumeration, so
     %
@@ -1083,7 +1082,7 @@
         Functor, Arity, Arguments).

 :- pred deconstruct(T, type_info, type_ctor_info, type_ctor_rep,
-    noncanon_handling, string, int, list(std_util.univ)).
+    noncanon_handling, string, int, list(univ)).
 :- mode deconstruct(in, in, in, in, in(do_not_allow), out, out, out) is det.
 :- mode deconstruct(in, in, in, in, in(canonicalize), out, out, out) is det.
 :- mode deconstruct(in, in, in, in,
@@ -1134,7 +1133,7 @@
             Functor = FunctorDesc ^ du_functor_name,
             Arity = FunctorDesc ^ du_functor_arity,
             Arguments = iterate(0, Arity - 1,
-                (func(X) = std_util.univ(
+                (func(X) = univ(
                     get_arg(Term, X, SecTagLocn, FunctorDesc, TypeInfo))
                 ))
         ;
@@ -1149,7 +1148,7 @@
             Functor = FunctorDesc ^ du_functor_name,
             Arity = FunctorDesc ^ du_functor_arity,
             Arguments = iterate(0, Arity - 1,
-                (func(X) = std_util.univ(
+                (func(X) = univ(
                     get_arg(Term, X, SecTagLocn, FunctorDesc, TypeInfo))
                 ))
         ;
@@ -1234,7 +1233,7 @@
         list.map_foldl(
             (pred(TI::in, U::out, Index::in, Next::out) is det :-
                 SubTerm = get_subterm(TI, Term, Index, 0),
-                U = std_util.univ(SubTerm),
+                U = univ(SubTerm),
                 Next = Index + 1
             ), TypeArgs, Arguments, 0, _)
     ;
@@ -1289,7 +1288,7 @@
         Functor = "<<array>>",
         Arity = array.size(Array),
         Arguments = array.foldr(
-            (func(Elem, List) = [std_util.univ(Elem) | List]),
+            (func(Elem, List) = [univ(Elem) | List]),
             Array, [])
     ;
         TypeCtorRep = succip,
@@ -1395,8 +1394,8 @@
 :- pred det_dynamic_cast(T::in, U::out) is det.

 det_dynamic_cast(Term, Actual) :-
-    std_util.type_to_univ(Term, Univ),
-    std_util.det_univ_to_type(Univ, Actual).
+    type_to_univ(Term, Univ),
+    det_univ_to_type(Univ, Actual).

 :- pred same_array_elem_type(array(T)::unused, T::unused) is det.

@@ -1406,7 +1405,7 @@
     notag_ground_usereq; reserved_addr_usereq).

 :- pred handle_usereq_type(T, type_info, type_ctor_info, type_ctor_rep,
-        noncanon_handling, string, int, list(std_util.univ)).
+        noncanon_handling, string, int, list(univ)).

 :- mode handle_usereq_type(in, in, in, in(usereq),
     in(do_not_allow), out, out, out) is erroneous.
@@ -1546,7 +1545,7 @@
             Arity = TypeCtorInfo ^ type_ctor_arity,
             StartRegionSize = 1
         ),
-        ArgTypeInfo0 = std_util.no,
+        ArgTypeInfo0 = maybe.no,
         UpperBound = Arity + StartRegionSize - 1,

         iterate_foldl(StartRegionSize, UpperBound,
@@ -1559,23 +1558,23 @@
                 ->
                     TI = TI0
                 ;
-                    TI0 = std_util.yes(TypeInfo0)
+                    TI0 = maybe.yes(TypeInfo0)
                 ->
                     unsafe_promise_unique(TypeInfo0, TypeInfo1),
                     update_type_info_index(I, ETypeInfo, TypeInfo1, TypeInfo),
-                    TI = std_util.yes(TypeInfo)
+                    TI = maybe.yes(TypeInfo)
                 ;
                     NewTypeInfo0 = new_type_info(CastTypeInfo, UpperBound),
                     update_type_info_index(I, ETypeInfo, NewTypeInfo0,
                         NewTypeInfo),
-                    TI = std_util.yes(NewTypeInfo)
+                    TI = maybe.yes(NewTypeInfo)
                 )
             ), ArgTypeInfo0, MaybeArgTypeInfo),
         (
-            MaybeArgTypeInfo = std_util.yes(ArgTypeInfo1),
+            MaybeArgTypeInfo = maybe.yes(ArgTypeInfo1),
             ArgTypeInfo = ArgTypeInfo1
         ;
-            MaybeArgTypeInfo = std_util.no,
+            MaybeArgTypeInfo = maybe.no,
             ArgTypeInfo = CastTypeInfo
         )
     ).
Index: library/set_ordlist.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/set_ordlist.m,v
retrieving revision 1.24
diff -u -r1.24 set_ordlist.m
--- library/set_ordlist.m	7 Mar 2006 22:23:48 -0000	1.24
+++ library/set_ordlist.m	28 Mar 2006 04:31:16 -0000
@@ -19,6 +19,8 @@
 :- import_module bool.
 :- import_module list.

+%--------------------------------------------------------------------------%
+
 :- type set_ordlist(_T).

 	% `set_ordlist.list_to_set(List, Set)' is true iff `Set' is the set
@@ -270,8 +272,7 @@

 :- implementation.

-:- import_module list.
-:- import_module std_util.
+%-----------------------------------------------------------------------------%

 :- type set_ordlist(T)	==	  list(T).

Index: library/set_unordlist.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/set_unordlist.m,v
retrieving revision 1.25
diff -u -r1.25 set_unordlist.m
--- library/set_unordlist.m	7 Mar 2006 22:23:48 -0000	1.25
+++ library/set_unordlist.m	28 Mar 2006 04:30:50 -0000
@@ -19,6 +19,8 @@
 :- import_module bool.
 :- import_module list.

+%--------------------------------------------------------------------------%
+
 :- type set_unordlist(_T).

 	% `set_unordlist.list_to_set(List, Set)' is true iff `Set' is the set
@@ -240,11 +242,11 @@
 :- mode set_unordlist.divide(pred(in) is semidet, in, out, out) is det.

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

 :- implementation.

-:- import_module list.
-:- import_module std_util.
+%--------------------------------------------------------------------------%

 :- type set_unordlist(T) ==	  list(T).

Index: library/sparse_bitset.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/sparse_bitset.m,v
retrieving revision 1.27
diff -u -r1.27 sparse_bitset.m
--- library/sparse_bitset.m	7 Mar 2006 22:23:48 -0000	1.27
+++ library/sparse_bitset.m	28 Mar 2006 04:30:08 -0000
@@ -5,11 +5,11 @@
 % 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: sparse_bitset.m.
-% Author: stayl
+% Author: stayl.
 % Stability: medium.
-%
+
 % This module provides an ADT for storing sets of integers.
 % If the integers stored are closely grouped, a sparse_bitset
 % is much more compact than the representation provided by set.m,
@@ -36,11 +36,11 @@
 % In the asymptotic complexities of the operations below,
 % `rep_size(Set)' is the number of pairs needed to represent `Set',
 % and `card(Set)' is the number of elements in `Set'.
-%
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
-:- module sparse_bitset.

+:- module sparse_bitset.
 :- interface.

 :- import_module enum.
@@ -49,6 +49,8 @@

 :- use_module set.

+%-----------------------------------------------------------------------------%
+
 :- type sparse_bitset(T). % <= enum(T).

     % Return an empty set.
@@ -386,7 +388,8 @@
 :- import_module int.
 :- import_module list.
 :- import_module require.
-:- import_module std_util.
+
+%-----------------------------------------------------------------------------%

     % The number of variables for most procedures
     % should fit into one or two words.
Index: library/stack.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/stack.m,v
retrieving revision 1.23
diff -u -r1.23 stack.m
--- library/stack.m	7 Mar 2006 22:23:48 -0000	1.23
+++ library/stack.m	28 Mar 2006 04:29:31 -0000
@@ -19,6 +19,8 @@
 :- interface.
 :- import_module list.

+%--------------------------------------------------------------------------%
+
 :- type stack(T).

 	% `stack.init(Stack)' is true iff `Stack' is an empty stack.
@@ -86,7 +88,8 @@
 :- implementation.

 :- import_module require.
-:- import_module std_util.
+
+%--------------------------------------------------------------------------%

 :- type stack(T) == list(T).

Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.309
diff -u -r1.309 std_util.m
--- library/std_util.m	28 Mar 2006 08:07:27 -0000	1.309
+++ library/std_util.m	29 Mar 2006 05:02:26 -0000
@@ -8,10 +8,25 @@

 % File: std_util.m.
 % Main author: fjh.
-% Stability: medium.
+% Stability: high.

-% This file is intended for all the useful standard utilities
-% that don't belong elsewhere, like <stdlib.h> in C.
+% This file contains higher-order programming constructs and other
+% useful standard utilities.
+
+% NOTE: fomerly this module contained considerably more functionality but
+%       most of that has now been moved to other modules.  In particular:
+%
+%       * the `univ' type is now defined in the module univ.
+%
+%       * the `maybe' and `maybe_error' types are now defined in the module
+%         maybe.
+%
+%       * the `unit' type is now defined in the module unit.
+%
+%       * the `pair' type is now defined in the module pair.
+
+% This module also used to define a number of RTTI access predicates.  These
+% are now to be found in the modules type_desc, construct and deconstruct.

 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -20,160 +35,66 @@
 :- interface.

 :- import_module bool.
+:- import_module int.
 :- import_module list.
+:- import_module maybe.
 :- import_module set.
-:- import_module type_desc.

 %-----------------------------------------------------------------------------%
 %
-% The universal type `univ'
+% General purpose higher-order programming constructs
 %

-    % An object of type `univ' can hold the type and value of an object of any
-    % other type.
-:- type univ.
-
-    % type_to_univ(Object, Univ):
-    %
-    % True iff the type stored in `Univ' is the same as the type of `Object',
-    % and the value stored in `Univ' is equal to the value of `Object'.
-    %
-    % Operational, the forwards mode converts an object to type `univ',
-    % while the reverse mode converts the value stored in `Univ'
-    % to the type of `Object', but fails if the type stored in `Univ'
-    % does not match the type of `Object'.
-    %
-:- pred type_to_univ(T, univ).
-:- mode type_to_univ(di, uo) is det.
-:- mode type_to_univ(in, out) is det.
-:- mode type_to_univ(out, in) is semidet.
-
-    % univ_to_type(Univ, Object) :- type_to_univ(Object, Univ).
+    % compose(F, G, X) = F(G(X))
     %
-:- pred univ_to_type(univ, T).
-:- mode univ_to_type(in, out) is semidet.
-:- mode univ_to_type(out, in) is det.
-:- mode univ_to_type(uo, di) is det.
-
-    % The function univ/1 provides the same functionality as type_to_univ/2.
-    % univ(Object) = Univ :- type_to_univ(Object, Univ).
+    % Function composition.
+    % XXX It would be nice to have infix `o' or somesuch for this.
     %
-:- func univ(T) = univ.
-:- mode univ(in) = out is det.
-:- mode univ(di) = uo is det.
-:- mode univ(out) = in is semidet.
+:- func compose(func(T2) = T3, func(T1) = T2, T1) = T3.

-    % det_univ_to_type(Univ, Object):
-    %
-    % The same as the forwards mode of univ_to_type, but aborts
-    % if univ_to_type fails.
+    % converse(F, X, Y) = F(Y, X).
     %
-:- pred det_univ_to_type(univ::in, T::out) is det.
+:- func converse(func(T1, T2) = T3, T2, T1) = T3.

-    % univ_type(Univ):
+    % pow(F, N, X) = F^N(X)
     %
-    % Returns the type_desc for the type stored in `Univ'.
+    % Function exponentiation.
     %
-:- func univ_type(univ) = type_desc.type_desc.
+:- func pow(func(T) = T, int, T) = T.

-    % univ_value(Univ):
-    %
-    % Returns the value of the object stored in Univ.
+    % The identity function.
     %
-:- some [T] func univ_value(univ) = T.
+:- func id(T) = T.

 %-----------------------------------------------------------------------------%
-%
-% The "maybe" type
-%

-:- type maybe(T) ---> no ; yes(T).
-:- inst maybe(I) ---> no ; yes(I).
-
-:- type maybe_error ---> ok ; error(string).
-:- type maybe_error(T) ---> ok(T) ; error(string).
-:- inst maybe_error(I) ---> ok(I) ; error(ground).
-
-    % map_maybe(P, yes(Value0), yes(Value)) :- P(Value, Value).
-    % map_maybe(_, no, no).
-    %
-:- pred map_maybe(pred(T, U), maybe(T), maybe(U)).
-:- mode map_maybe(pred(in, out) is det, in, out) is det.
-:- mode map_maybe(pred(in, out) is semidet, in, out) is semidet.
-:- mode map_maybe(pred(in, out) is multi, in, out) is multi.
-:- mode map_maybe(pred(in, out) is nondet, in, out) is nondet.
-
-    % map_maybe(F, yes(Value)) = yes(F(Value)).
-    % map_maybe(_, no) = no.
+    % maybe_pred(Pred, X, Y) takes a closure Pred which transforms an
+    % input semideterministically. If calling the closure with the input
+    % X succeeds, Y is bound to `yes(Z)' where Z is the output of the
+    % call, or to `no' if the call fails.
     %
-:- func map_maybe(func(T) = U, maybe(T)) = maybe(U).
+:- pred maybe_pred(pred(T1, T2), T1, maybe(T2)).
+:- mode maybe_pred(pred(in, out) is semidet, in, out) is det.

-    % fold_maybe(P, yes(Value), Acc0, Acc) :- P(Value, Acc0, Acc).
-    % fold_maybe(_, no, Acc, Acc).
-    %
-:- pred fold_maybe(pred(T, U, U), maybe(T), U, U).
-:- mode fold_maybe(pred(in, in, out) is det, in, in, out) is det.
-:- mode fold_maybe(pred(in, in, out) is semidet, in, in, out) is semidet.
-:- mode fold_maybe(pred(in, di, uo) is det, in, di, uo) is det.
+:- func maybe_func(func(T1) = T2, T1) = maybe(T2).
+:- mode maybe_func(func(in) = out is semidet, in) = out is det.

-    % fold_maybe(F, yes(Value), Acc0) = F(Acc0).
-    % fold_maybe(_, no, Acc) = Acc.
-    %
-:- func fold_maybe(func(T, U) = U, maybe(T), U) = U.
+%-----------------------------------------------------------------------------%

-    % map_fold_maybe(P, yes(Value0), yes(Value), Acc0, Acc) :-
-    %       P(Value, Value, Acc0, Acc).
-    % map_fold_maybe(_, no, no, Acc, Acc).
+    % isnt(Pred, X) <=> not Pred(X)
     %
-:- pred map_fold_maybe(pred(T, U, Acc, Acc), maybe(T), maybe(U), Acc, Acc).
-:- mode map_fold_maybe(pred(in, out, in, out) is det, in, out, in, out) is det.
-:- mode map_fold_maybe(pred(in, out, di, uo) is det, in, out, di, uo) is det.
-
-    % As above, but with two accumulators.
+    % This is useful in higher order programming, e.g.
+    %   Odds  = list.filter(odd, Xs)
+    %   Evens = list.filter(isnt(odd), Xs)
     %
-:- pred map_fold2_maybe(pred(T, U, Acc1, Acc1, Acc2, Acc2),
-    maybe(T), maybe(U), Acc1, Acc1, Acc2, Acc2).
-:- mode map_fold2_maybe(pred(in, out, in, out, in, out) is det, in, out,
-    in, out, in, out) is det.
-:- mode map_fold2_maybe(pred(in, out, in, out, di, uo) is det,
-    in, out, in, out, di, uo) is det.
+:- pred isnt(pred(T)::(pred(in) is semidet), T::in) is semidet.

 %-----------------------------------------------------------------------------%
-%
-% The "unit" type - stores no information at all.
-%
-
-:- type unit        --->    unit.
-
-:- type unit(T)     --->    unit1.
-
 %-----------------------------------------------------------------------------%
 %
-% The "pair" type.  Useful for many purposes.
+% All-solutions predicates
 %

-:- type pair(T1, T2)
-    --->    (T1 - T2).
-:- type pair(T) ==  pair(T, T).
-
-:- inst pair(I1, I2)
-    --->    (I1 - I2).
-:- inst pair(I) ==  pair(I, I).
-
-    % Return the first element of the pair.
-    %
-:- pred fst(pair(X, Y)::in, X::out) is det.
-:- func fst(pair(X, Y)) = X.
-
-    % Return the second element of the pair.
-    %
-:- pred snd(pair(X, Y)::in, Y::out) is det.
-:- func snd(pair(X, Y)) = Y.
-
-:- func pair(T1, T2) = pair(T1, T2).
-
-%-----------------------------------------------------------------------------%
-
 % NOTE: the procedures in this section are all obsolete and will be deleted
 %       in a later release.  New code should use the versions defined in
 %       solutions.m instead.
@@ -330,115 +251,35 @@
     is cc_multi.

 %-----------------------------------------------------------------------------%
-%
-% General purpose higher-order programming constructs.
-%
-
-    % compose(F, G, X) = F(G(X))
-    %
-    % Function composition.
-    % XXX It would be nice to have infix `o' or somesuch for this.
-    %
-:- func compose(func(T2) = T3, func(T1) = T2, T1) = T3.
-
-    % converse(F, X, Y) = F(Y, X).
-    %
-:- func converse(func(T1, T2) = T3, T2, T1) = T3.
-
-    % pow(F, N, X) = F^N(X)
-    %
-    % Function exponentiation.
-    %
-:- func pow(func(T) = T, int, T) = T.
-
-    % The identity function.
-    %
-:- func id(T) = T.
-
-%-----------------------------------------------------------------------------%
-
-    % maybe_pred(Pred, X, Y) takes a closure Pred which transforms an
-    % input semideterministically. If calling the closure with the input
-    % X succeeds, Y is bound to `yes(Z)' where Z is the output of the
-    % call, or to `no' if the call fails.
-    %
-:- pred maybe_pred(pred(T1, T2), T1, maybe(T2)).
-:- mode maybe_pred(pred(in, out) is semidet, in, out) is det.
-
-:- func maybe_func(func(T1) = T2, T1) = maybe(T2).
-:- mode maybe_func(func(in) = out is semidet, in) = out is det.
-
-%-----------------------------------------------------------------------------%
-
-    % isnt(Pred, X) <=> not Pred(X)
-    %
-    % This is useful in higher order programming, e.g.
-    %   Odds  = list.filter(odd, Xs)
-    %   Evens = list.filter(isnt(odd), Xs)
-    %
-:- pred isnt(pred(T)::(pred(in) is semidet), T::in) is semidet.
-
-%-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%

 :- implementation.

-:- import_module bool.
-:- import_module construct.
-:- import_module deconstruct.
-:- import_module int.
-:- import_module require.
-:- import_module set.
-:- import_module string.
-
-:- use_module private_builtin. % for the `heap_pointer' type.
 :- use_module solutions.

 %-----------------------------------------------------------------------------%

-map_maybe(_, no, no).
-map_maybe(P, yes(T0), yes(T)) :- P(T0, T).
+maybe_pred(Pred, X, Y) :-
+    Y = ( Pred(X, Z) -> yes(Z) ; no ).

-map_maybe(_, no) = no.
-map_maybe(F, yes(T)) = yes(F(T)).
+maybe_func(PF, X) =
+    ( if Y = PF(X) then yes(Y) else no ).

-fold_maybe(P, yes(Value), Acc0, Acc) :- P(Value, Acc0, Acc).
-fold_maybe(_, no, Acc, Acc).
+compose(F, G, X) =
+    F(G(X)).

-fold_maybe(F, yes(Value), Acc0) = F(Value, Acc0).
-fold_maybe(_, no, Acc) = Acc.
-
-map_fold_maybe(_, no, no, Acc, Acc).
-map_fold_maybe(P, yes(T0), yes(T), Acc0, Acc) :-
-    P(T0, T, Acc0, Acc).
-
-map_fold2_maybe(_, no, no, A, A, B, B).
-map_fold2_maybe(P, yes(T0), yes(T), A0, A, B0, B) :-
-    P(T0, T, A0, A, B0, B).
-
-%   Is this really useful?
-% % for use in lambda expressions where the type of functor '-' is ambiguous
-% :- pred pair(X, Y, pair(X, Y)).
-% :- mode pair(in, in, out) is det.
-% :- mode pair(out, out, in) is det.
-%
-% pair(X, Y, X-Y).
+converse(F, X, Y) =
+    F(Y, X).

-fst(X-_Y) = X.
-fst(P, X) :-
-    X = fst(P).
-
-snd(_X-Y) = Y.
-snd(P, X) :-
-    X = snd(P).
+pow(F, N, X) =
+    ( if N = 0 then X else pow(F, N - 1, F(X)) ).

-maybe_pred(Pred, X, Y) :-
-    ( call(Pred, X, Z) ->
-        Y = yes(Z)
-    ;
-        Y = no
-    ).
+isnt(P, X) :-
+    not P(X).
+
+id(X) = X.

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

 % NOTE: the implementations for these predicates is in solutions.m.
@@ -465,89 +306,11 @@
     solutions.do_while(GeneratorPred, CollectorPred,
         Accumulator0, Accumulator).

-%-----------------------------------------------------------------------------%
-
-    % We call the constructor for univs `univ_cons' to avoid ambiguity
-    % with the univ/1 function which returns a univ.
-:- type univ
-    --->    some [T] univ_cons(T).
-
-univ_to_type(Univ, X) :- type_to_univ(X, Univ).
-
-univ(X) = Univ :- type_to_univ(X, Univ).
-
-det_univ_to_type(Univ, X) :-
-    ( type_to_univ(X0, Univ) ->
-        X = X0
-    ;
-        UnivTypeName = type_desc.type_name(univ_type(Univ)),
-        ObjectTypeName = type_desc.type_name(type_desc.type_of(X)),
-        string.append_list(["det_univ_to_type: conversion failed\\n",
-            "\tUniv Type: ", UnivTypeName,
-            "\\n\tObject Type: ", ObjectTypeName], ErrorString),
-        error(ErrorString)
-    ).
-
-univ_value(univ_cons(X)) = X.
-
-:- pragma promise_pure(type_to_univ/2).
-
-type_to_univ(T::di, Univ::uo) :-
-    Univ0 = 'new univ_cons'(T),
-    unsafe_promise_unique(Univ0, Univ).
-type_to_univ(T::in, Univ::out) :-
-    Univ0 = 'new univ_cons'(T),
-    unsafe_promise_unique(Univ0, Univ).
-type_to_univ(T::out, Univ::in) :-
-    Univ = univ_cons(T0),
-    private_builtin.typed_unify(T0, T).
-
-univ_type(Univ) = type_desc.type_of(univ_value(Univ)).
-
-:- pred construct_univ(T, univ).
-:- mode construct_univ(in, out) is det.
-:- pragma export(construct_univ(in, out), "ML_construct_univ").
-
-construct_univ(X, Univ) :-
-    Univ = univ(X).
-
-:- some [T] pred unravel_univ(univ, T).
-:- mode unravel_univ(in, out) is det.
-:- pragma export(unravel_univ(in, out), "ML_unravel_univ").
-
-unravel_univ(Univ, X) :-
-    univ_value(Univ) = X.
-
-%-----------------------------------------------------------------------------%
-%-----------------------------------------------------------------------------%
-% Ralph Becket <rwab1 at cam.sri.com> 24/04/99
-%   Function forms added.
-
-pair(X, Y) =
-    X-Y.
-
-maybe_func(PF, X) =
-    ( if Y = PF(X) then yes(Y) else no ).
-
-compose(F, G, X) =
-    F(G(X)).
-
-converse(F, X, Y) =
-    F(Y, X).
-
-pow(F, N, X) =
-    ( if N = 0 then X else pow(F, N - 1, F(X)) ).
-
-isnt(P, X) :-
-    not P(X).
-
-id(X) = X.
-
 solutions(P) = solutions.solutions(P).

 solutions_set(P) = solutions.solutions_set(P).

 aggregate(P, F, Acc0) = solutions.aggregate(P, F, Acc0).

-%------------------------------------------------------------------------------%
-%------------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
Index: library/store.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/store.m,v
retrieving revision 1.56
diff -u -r1.56 store.m
--- library/store.m	29 Mar 2006 01:35:19 -0000	1.56
+++ library/store.m	29 Mar 2006 01:36:50 -0000
@@ -5,11 +5,11 @@
 % 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: store.m.
 % Main author: fjh.
 % Stability: low.
-%
+
 % This file provides facilities for manipulating mutable stores.
 % A store can be considered a mapping from abstract keys to their values.
 % A store holds a set of nodes, each of which may contain a value of any
@@ -24,7 +24,7 @@
 % mutvars can only be updated atomically,
 % whereas it is possible to update individual fields of a reference
 % one at a time (presuming the reference refers to a structured term).
-%
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%

Index: library/string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.243
diff -u -r1.243 string.m
--- library/string.m	22 Mar 2006 02:56:19 -0000	1.243
+++ library/string.m	29 Mar 2006 01:41:49 -0000
@@ -6,6 +6,7 @@
 % Public License - see the file COPYING.LIB in the Mercury distribution.
 %---------------------------------------------------------------------------%

+% File: string.m.
 % Main authors: fjh, petdr.
 % Stability: medium to high.

@@ -17,6 +18,7 @@
 % avoid creating strings that might contain null characters.

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

 :- module string.
 :- interface.
@@ -26,6 +28,8 @@
 :- import_module list.
 :- import_module ops.

+%-----------------------------------------------------------------------------%
+
     % Determine the length of a string.
     % An empty string has length zero.
     %
@@ -743,6 +747,7 @@
 :- func string.word_wrap(string, int, string) = string.

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

 :- implementation.

@@ -751,13 +756,17 @@
 :- import_module float.
 :- import_module int.
 :- import_module integer.
+:- import_module maybe.
 :- import_module require.
 :- import_module std_util.
 :- import_module type_desc.
+:- import_module univ.

 :- use_module rtti_implementation.
 :- use_module term_io.

+%-----------------------------------------------------------------------------%
+
 string.replace(Str, Pat, Subst, Result) :-
     sub_string_search(Str, Pat, Index),

Index: library/svvarset.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/svvarset.m,v
retrieving revision 1.5
diff -u -r1.5 svvarset.m
--- library/svvarset.m	7 Mar 2006 22:23:50 -0000	1.5
+++ library/svvarset.m	23 Mar 2006 06:02:13 -0000
@@ -19,9 +19,9 @@
 :- interface.

 :- import_module list.
+:- import_module maybe.
 :- import_module set.
 :- import_module string.
-:- import_module std_util.
 :- import_module term.
 :- import_module varset.

Index: library/table_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/table_builtin.m,v
retrieving revision 1.50
diff -u -r1.50 table_builtin.m
--- library/table_builtin.m	7 Mar 2006 22:23:50 -0000	1.50
+++ library/table_builtin.m	27 Mar 2006 07:04:45 -0000
@@ -1389,11 +1389,11 @@
 :- implementation.

 :- import_module require.
-:- import_module std_util.
+:- import_module univ.

 :- pragma foreign_decl("C", "

-#include ""mercury_misc.h""     /* for MR_fatal_error(); */
+#include ""mercury_misc.h""         /* for MR_fatal_error(); */
 #include ""mercury_type_info.h""    /* for MR_TypeCtorInfo_Struct; */
 #include ""mercury_tabling.h""      /* for MR_TrieNode, etc. */

Index: library/term.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/term.m,v
retrieving revision 1.117
diff -u -r1.117 term.m
--- library/term.m	28 Mar 2006 08:07:28 -0000	1.117
+++ library/term.m	28 Mar 2006 14:00:10 -0000
@@ -16,6 +16,7 @@
 % thing can be made to be of different types so they don't get mixed up.

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

 :- module term.
 :- interface.
@@ -23,8 +24,8 @@
 :- import_module enum.
 :- import_module list.
 :- import_module map.
-:- import_module std_util.
 :- import_module type_desc.
+:- import_module univ.

 %-----------------------------------------------------------------------------%

@@ -469,7 +470,6 @@
 :- import_module float.
 :- import_module int.
 :- import_module require.
-:- import_module std_util.
 :- import_module string.
 :- import_module svmap.

@@ -623,8 +623,7 @@
     ).
 term_to_univ_special_case(_, "builtin", "c_pointer", _, _, _, _, _) :-
     fail.
-term_to_univ_special_case(_, "std_util", "univ", [],
-        Term, _, _, Result) :-
+term_to_univ_special_case(_, "univ", "univ", [], Term, _, _, Result) :-
     % Implementing this properly would require keeping a global table mapping
     % from type names to type_infos for all of the types in the program...
     % so for the moment, we only allow it for basic types.
@@ -763,7 +762,7 @@
         functor(atom("type_info"), [Term], Context)) :-
     det_univ_to_type(Univ, TypeInfo),
     type_info_to_term(Context, TypeInfo, Term).
-univ_to_term_special_case("std_util", "univ", [], Univ, Context, Term) :-
+univ_to_term_special_case("univ", "univ", [], Univ, Context, Term) :-
     det_univ_to_type(Univ, NestedUniv),
     Term = functor(atom("univ"),
         % XXX what operator should we use for type qualification?
Index: library/term_io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/term_io.m,v
retrieving revision 1.77
diff -u -r1.77 term_io.m
--- library/term_io.m	7 Mar 2006 22:23:50 -0000	1.77
+++ library/term_io.m	28 Mar 2006 04:28:37 -0000
@@ -5,15 +5,16 @@
 % 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: term_io.m.
 % Main author: fjh.
 % Stability: medium to high.
-%
+
 % This file encapsulates all the term I/O.
 % This exports predicates to read and write terms in the
 % nice ground representation provided in term.m.
-%
+
+%-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%

 :- module term_io.
@@ -25,6 +26,8 @@
 :- import_module term.
 :- import_module varset.

+%-----------------------------------------------------------------------------%
+
 % External interface: exported predicates

 % The following are not yet implemented.
@@ -180,9 +183,10 @@
 :- import_module list.
 :- import_module parser.
 :- import_module require.
-:- import_module std_util.
 :- import_module string.

+%-----------------------------------------------------------------------------%
+
 term_io.read_term(Result, !IO) :-
     io.get_op_table(Ops, !IO),
     term_io.read_term_with_op_table(Ops, Result, !IO).
Index: library/term_size_prof_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/term_size_prof_builtin.m,v
retrieving revision 1.6
diff -u -r1.6 term_size_prof_builtin.m
--- library/term_size_prof_builtin.m	7 Mar 2006 22:23:50 -0000	1.6
+++ library/term_size_prof_builtin.m	28 Mar 2006 04:28:06 -0000
@@ -5,19 +5,18 @@
 % 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: term_size_prof.m.
 % Author: zs.
 % Stability: low.
-%
+
 % This file is automatically imported into every module when term size
 % profiling is enabled. It contains support predicates used for term size
 % profiling.
-%
+
 %---------------------------------------------------------------------------%

 :- module term_size_prof_builtin.
-
 :- interface.

     % measure_size(Term, Size): return the size of Term as Size.
@@ -78,7 +77,9 @@

 :- import_module int.
 :- import_module require.
-:- import_module std_util.
+
+%---------------------------------------------------------------------------%
+

 :- pragma foreign_decl("C", "
 #ifndef MR_TERM_SIZE_PROFILING_GUARD
Index: library/term_to_xml.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/term_to_xml.m,v
retrieving revision 1.11
diff -u -r1.11 term_to_xml.m
--- library/term_to_xml.m	22 Mar 2006 02:56:20 -0000	1.11
+++ library/term_to_xml.m	27 Mar 2006 07:13:24 -0000
@@ -5,11 +5,11 @@
 % 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: term_to_xml.m.
 % Main author: maclarty.
 % Stability: low.
-%
+
 % This module provides two mechanisms for converting Mercury terms
 % to XML documents.
 %
@@ -46,7 +46,7 @@
 %
 % In both methods the XML document can be annotated with a stylesheet
 % reference.
-%
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%

@@ -57,7 +57,7 @@
 :- import_module int.
 :- import_module io.
 :- import_module list.
-:- import_module std_util.
+:- import_module maybe.
 :- import_module type_desc.

 %-----------------------------------------------------------------------------%
@@ -529,6 +529,8 @@
 :- import_module map.
 :- import_module require.
 :- import_module string.
+:- import_module unit.
+:- import_module univ.

 %-----------------------------------------------------------------------------%

Index: library/time.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/time.m,v
retrieving revision 1.50
diff -u -r1.50 time.m
--- library/time.m	7 Mar 2006 22:23:50 -0000	1.50
+++ library/time.m	23 Mar 2006 05:11:01 -0000
@@ -22,7 +22,7 @@
 :- interface.

 :- import_module io.
-:- import_module std_util.
+:- import_module maybe.

     % The `clock_t' type represents times measured in clock ticks.
     % NOTE: the unit used for a value of this type depends on whether it was
Index: library/tree234.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/tree234.m,v
retrieving revision 1.51
diff -u -r1.51 tree234.m
--- library/tree234.m	7 Mar 2006 22:23:50 -0000	1.51
+++ library/tree234.m	23 Mar 2006 06:21:50 -0000
@@ -216,8 +216,8 @@

 :- import_module bool.
 :- import_module int.
+:- import_module pair.
 :- import_module require.
-:- import_module std_util.

 :- type tree234(K, V)
     --->    empty
Index: library/type_desc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/type_desc.m,v
retrieving revision 1.36
diff -u -r1.36 type_desc.m
--- library/type_desc.m	7 Mar 2006 22:23:51 -0000	1.36
+++ library/type_desc.m	28 Mar 2006 04:47:59 -0000
@@ -14,7 +14,6 @@
 %-----------------------------------------------------------------------------%

 :- module type_desc.
-
 :- interface.

 :- import_module list.
@@ -214,7 +213,6 @@
 :- import_module string.

 :- use_module    rtti_implementation.
-:- use_module    std_util.

 :- pragma foreign_decl("C", "
 #include ""mercury_heap.h"" /* for MR_incr_hp_msg() etc. */
@@ -340,7 +338,7 @@
 is_univ_pseudo_type_desc(_PseudoTypeDesc, -1) :-
     % The backends in which we use this definition of this predicate
     % don't yet support pseudo_type_descs.
-    std_util.semidet_fail.
+    semidet_fail.

 :- pred is_exist_pseudo_type_desc(pseudo_type_desc::in, int::out) is semidet.

@@ -364,7 +362,7 @@
 is_exist_pseudo_type_desc(_PseudoTypeDesc, -1) :-
     % The backends in which we use this definition of this predicate
     % don't yet support pseudo_type_descs.
-    std_util.semidet_fail.
+    semidet_fail.

 :- pragma foreign_proc("C",
     type_desc_to_pseudo_type_desc(TypeDesc::in) = (PseudoTypeDesc::out),
Index: library/univ.m
===================================================================
RCS file: library/univ.m
diff -N library/univ.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ library/univ.m	27 Mar 2006 07:04:59 -0000
@@ -0,0 +1,144 @@
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%-----------------------------------------------------------------------------%
+% Copyright (C) 1994-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: univ.m.
+% Main author: fjh.
+% Stability: medium.
+
+% The universal type `univ'
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- module univ.
+:- interface.
+
+:- import_module type_desc.
+
+%-----------------------------------------------------------------------------%
+
+    % An object of type `univ' can hold the type and value of an object of any
+    % other type.
+    %
+:- type univ.
+
+    % type_to_univ(Object, Univ).
+    %
+    % True iff the type stored in `Univ' is the same as the type of `Object',
+    % and the value stored in `Univ' is equal to the value of `Object'.
+    %
+    % Operational, the forwards mode converts an object to type `univ',
+    % while the reverse mode converts the value stored in `Univ'
+    % to the type of `Object', but fails if the type stored in `Univ'
+    % does not match the type of `Object'.
+    %
+:- pred type_to_univ(T, univ).
+:- mode type_to_univ(di, uo) is det.
+:- mode type_to_univ(in, out) is det.
+:- mode type_to_univ(out, in) is semidet.
+
+    % univ_to_type(Univ, Object) :- type_to_univ(Object, Univ).
+    %
+:- pred univ_to_type(univ, T).
+:- mode univ_to_type(in, out) is semidet.
+:- mode univ_to_type(out, in) is det.
+:- mode univ_to_type(uo, di) is det.
+
+    % The function univ/1 provides the same functionality as type_to_univ/2.
+    % univ(Object) = Univ :- type_to_univ(Object, Univ).
+    %
+:- func univ(T) = univ.
+:- mode univ(in) = out is det.
+:- mode univ(di) = uo is det.
+:- mode univ(out) = in is semidet.
+
+    % det_univ_to_type(Univ, Object).
+    %
+    % The same as the forwards mode of univ_to_type, but aborts
+    % if univ_to_type fails.
+    %
+:- pred det_univ_to_type(univ::in, T::out) is det.
+
+    % univ_type(Univ).
+    %
+    % Returns the type_desc for the type stored in `Univ'.
+    %
+:- func univ_type(univ) = type_desc.
+
+    % univ_value(Univ).
+    %
+    % Returns the value of the object stored in Univ.
+    %
+:- some [T] func univ_value(univ) = T.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module require.
+:- import_module list.
+:- import_module string.
+
+%-----------------------------------------------------------------------------%
+
+    % We call the constructor for univs `univ_cons' to avoid ambiguity
+    % with the univ/1 function which returns a univ.
+    %
+:- type univ
+    --->    some [T] univ_cons(T).
+
+univ_to_type(Univ, X) :- type_to_univ(X, Univ).
+
+univ(X) = Univ :- type_to_univ(X, Univ).
+
+det_univ_to_type(Univ, X) :-
+    ( type_to_univ(X0, Univ) ->
+        X = X0
+    ;
+        UnivTypeName = type_name(univ_type(Univ)),
+        ObjectTypeName = type_name(type_of(X)),
+        string.append_list(["det_univ_to_type: conversion failed\\n",
+            "\tUniv Type: ", UnivTypeName,
+            "\\n\tObject Type: ", ObjectTypeName], ErrorString),
+        error(ErrorString)
+    ).
+
+univ_value(univ_cons(X)) = X.
+
+:- pragma promise_pure(type_to_univ/2).
+
+type_to_univ(T::di, Univ::uo) :-
+    Univ0 = 'new univ_cons'(T),
+    unsafe_promise_unique(Univ0, Univ).
+type_to_univ(T::in, Univ::out) :-
+    Univ0 = 'new univ_cons'(T),
+    unsafe_promise_unique(Univ0, Univ).
+type_to_univ(T::out, Univ::in) :-
+    Univ = univ_cons(T0),
+    private_builtin.typed_unify(T0, T).
+
+univ_type(Univ) = type_desc.type_of(univ_value(Univ)).
+
+:- pred construct_univ(T, univ).
+:- mode construct_univ(in, out) is det.
+:- pragma export(construct_univ(in, out), "ML_construct_univ").
+
+construct_univ(X, Univ) :-
+    Univ = univ(X).
+
+:- some [T] pred unravel_univ(univ, T).
+:- mode unravel_univ(in, out) is det.
+:- pragma export(unravel_univ(in, out), "ML_unravel_univ").
+
+unravel_univ(Univ, X) :-
+    univ_value(Univ) = X.
+
+%-----------------------------------------------------------------------------%
+:- end_module univ.
+%-----------------------------------------------------------------------------%
Index: library/varset.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/varset.m,v
retrieving revision 1.76
diff -u -r1.76 varset.m
--- library/varset.m	7 Mar 2006 22:23:51 -0000	1.76
+++ library/varset.m	23 Mar 2006 06:22:59 -0000
@@ -34,8 +34,8 @@
 :- import_module assoc_list.
 :- import_module list.
 :- import_module map.
+:- import_module maybe.
 :- import_module set.
-:- import_module std_util.
 :- import_module term.

 :- type varset(T).
@@ -256,6 +256,7 @@
 :- import_module int.
 :- import_module list.
 :- import_module map.
+:- import_module pair.
 :- import_module require.
 :- import_module set.
 :- import_module string.
Index: library/version_array2d.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/version_array2d.m,v
retrieving revision 1.2
diff -u -r1.2 version_array2d.m
--- library/version_array2d.m	16 Jun 2005 04:08:07 -0000	1.2
+++ library/version_array2d.m	28 Mar 2006 04:24:26 -0000
@@ -4,23 +4,26 @@
 % Public License - see the file COPYING.LIB in the Mercury distribution.
 % vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
 %-----------------------------------------------------------------------------%
-% version_array2d.m
-% Ralph Becket <rafe at cs.mu.oz.au>
-% Wed Jan 15 15:17:11 EST 2003
-%
+
+% File: version_array2d.m.
+% Author: Ralph Becket <rafe at cs.mu.oz.au>.
+% Stability: medium-low.
+
 % Two-dimensional rectangular (i.e. not ragged) version arrays.
 %
 % See the header comments in version_types.m for more details about version
 % structures.
-%
+
+%-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%

 :- module version_array2d.
-
 :- interface.

-:- import_module list.
 :- import_module int.
+:- import_module list.
+
+%-----------------------------------------------------------------------------%

     % A version_array2d is a two-dimensional version array stored in row-major
     % order (that is, the elements of the first row in left-to-right order,
@@ -106,10 +109,12 @@
 :- implementation.

 :- import_module require.
-:- import_module std_util.
 :- import_module string.
 :- import_module version_array.

+%-----------------------------------------------------------------------------%
+
+
     % version_array2d(Rows, Cols, Array)
     %
 :- type version_array2d(T) ---> version_array2d(int, int, version_array(T)).
Index: library/version_hash_table.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/version_hash_table.m,v
retrieving revision 1.5
diff -u -r1.5 version_hash_table.m
--- library/version_hash_table.m	22 Mar 2006 02:56:20 -0000	1.5
+++ library/version_hash_table.m	27 Mar 2006 07:14:04 -0000
@@ -4,10 +4,11 @@
 % Public License - see the file COPYING.LIB in the Mercury distribution.
 % vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
 %-----------------------------------------------------------------------------%
-% File: version_hash_table.m
-% Main author: rafe
-% Stability: low
-%
+
+% File: version_hash_table.m.
+% Main author: rafe.
+% Stability: low.
+
 % (See the header comments in version_types.m for an explanation of version
 % types.)
 %
@@ -16,11 +17,11 @@
 % implementation.  "Older" versions of the hash table are still
 % accessible, but will incurr a growing performance penalty as
 % more updates are made to the hash table.
-%
+
+%-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%

 :- module version_hash_table.
-
 :- interface.

 :- import_module assoc_list.
@@ -29,6 +30,8 @@
 :- import_module int.
 :- import_module string.

+%-----------------------------------------------------------------------------%
+
 :- type version_hash_table(K, V).

 :- type hash_pred(K) == ( pred(K,  int, int)        ).
@@ -144,6 +147,7 @@

 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
+
 :- implementation.

 :- import_module array.
@@ -152,11 +156,14 @@
 :- import_module exception.
 :- import_module list.
 :- import_module math.
+:- import_module pair.
 :- import_module require.
-:- import_module std_util.
 :- import_module type_desc.
+:- import_module univ.
 :- import_module version_array.

+%-----------------------------------------------------------------------------%
+
 :- type version_hash_table(K, V)
     --->    ht(
                 num_buckets             :: int,
Index: library/version_store.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/version_store.m,v
retrieving revision 1.2
diff -u -r1.2 version_store.m
--- library/version_store.m	16 Jun 2005 04:08:07 -0000	1.2
+++ library/version_store.m	28 Mar 2006 05:11:47 -0000
@@ -4,10 +4,10 @@
 % Public License - see the file COPYING.LIB in the Mercury distribution.
 % vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
 %-----------------------------------------------------------------------------%
-% version_store.m
-% Ralph Becket <rafe at cs.mu.oz.au>
-% Thu Jan 22 12:01:19 EST 2004
-%
+
+% File: version_store.m.
+% Author: Ralph Becket <rafe at cs.mu.oz.au>
+
 % (See the header comments in version_types.m for an explanation of version
 % types.)
 %
@@ -17,13 +17,14 @@
 % Note that, unlike ordinary stores, liveness of data is via the version store
 % rather than the mutvars.  This means that dead data (i.e.  whose mutvar is
 % out of scope) in a version_store may not be garbage collected.
-%
+
 %-----------------------------------------------------------------------------%

 :- module version_store.
-
 :- interface.

+%-----------------------------------------------------------------------------%
+
 :- type version_store(S).

 :- type mutvar(T, S).
@@ -99,9 +100,12 @@
 :- import_module counter.
 :- import_module int.
 :- import_module list.
-:- import_module std_util.
+:- import_module unit.
+:- import_module univ.
 :- import_module version_array.

+%-----------------------------------------------------------------------------%
+
     % Index 0 of the version_store contains the counter used to assign
     % new version store mutvars.  A mutvar is just an index into the
     % version_store.

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