[m-rev.] diff/for review: clean up library modules (part 3)
Julien Fischer
juliensf at cs.mu.OZ.AU
Fri Jan 21 15:38:49 AEDT 2005
Index: library/set_unordlist.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/set_unordlist.m,v
retrieving revision 1.22
diff -u -r1.22 set_unordlist.m
--- library/set_unordlist.m 18 Jan 2005 04:27:17 -0000 1.22
+++ library/set_unordlist.m 19 Jan 2005 03:03:55 -0000
@@ -21,7 +21,7 @@
% `set_unordlist__list_to_set(List, Set)' is true iff `Set' is the set
% containing only the members of `List'.
-
+ %
:- pred set_unordlist__list_to_set(list(T)::in, set_unordlist(T)::out) is det.
:- func set_unordlist__list_to_set(list(T)) = set_unordlist(T).
@@ -31,7 +31,7 @@
% `set_unordlist__sorted_list_to_set(List, Set)' is true iff `Set' is
% the set containing only the members of `List'. `List' must be sorted.
-
+ %
:- pred set_unordlist__sorted_list_to_set(list(T)::in, set_unordlist(T)::out)
is det.
:- func set_unordlist__sorted_list_to_set(list(T)) = set_unordlist(T).
@@ -42,19 +42,19 @@
% `set_unordlist__to_sorted_list(Set, List)' is true iff `List' is the
% list of all the members of `Set', in sorted order.
-
+ %
:- pred set_unordlist__to_sorted_list(set_unordlist(T)::in, list(T)::out)
is det.
:- func set_unordlist__to_sorted_list(set_unordlist(T)) = list(T).
% `set_unordlist__init(Set)' is true iff `Set' is an empty set.
-
+ %
:- pred set_unordlist__init(set_unordlist(_T)::uo) is det.
:- func set_unordlist__init = set_unordlist(T).
% `set_unordlist__singleton_set(Set, Elem)' is true iff `Set' is the set
% containing just the single element `Elem'.
-
+ %
:- pred set_unordlist__singleton_set(set_unordlist(T), T).
:- mode set_unordlist__singleton_set(in, out) is semidet.
:- mode set_unordlist__singleton_set(out, in) is det.
@@ -63,46 +63,46 @@
% `set_unordlist__equal(SetA, SetB)' is true iff
% `SetA' and `SetB' contain the same elements.
-
+ %
:- pred set_unordlist__equal(set_unordlist(T)::in, set_unordlist(T)::in)
is semidet.
% `set_unordlist__empty(Set)' is true iff `Set' is an empty set.
-
+ %
:- pred set_unordlist__empty(set_unordlist(_T)::in) is semidet.
% `set_unordlist__subset(SetA, SetB)' is true iff `SetA' is a subset of
% `SetB'.
-
+ %
:- pred set_unordlist__subset(set_unordlist(T)::in, set_unordlist(T)::in)
is semidet.
% `set_unordlist__superset(SetA, SetB)' is true iff `SetA' is a
% superset of `SetB'.
-
+ %
:- pred set_unordlist__superset(set_unordlist(T)::in, set_unordlist(T)::in)
is semidet.
% `set_unordlist__member(X, Set)' is true iff `X' is a member of `Set'.
-
+ %
:- pred set_unordlist__member(T, set_unordlist(T)).
:- mode set_unordlist__member(in, in) is semidet.
:- mode set_unordlist__member(out, in) is nondet.
% `set_unordlist__is_member(X, Set, Result)' returns
% `Result = yes' iff `X' is a member of `Set'.
-
+ %
:- pred set_unordlist__is_member(T::in, set_unordlist(T)::in, bool::out)
is det.
% `set_unordlist__contains(Set, X)' is true iff
% `X' is a member of `Set'.
-
+ %
:- pred set_unordlist__contains(set_unordlist(T)::in, T::in) is semidet.
% `set_unordlist__insert(Set0, X, Set)' is true iff `Set' is the union
% of `Set0' and the set containing only `X'.
-
+ %
:- pred set_unordlist__insert(set_unordlist(T), T, set_unordlist(T)).
:- mode set_unordlist__insert(di, di, uo) is det.
:- mode set_unordlist__insert(in, in, out) is det.
@@ -111,7 +111,7 @@
% `set_unordlist__insert_list(Set0, Xs, Set)' is true iff `Set' is the
% union of `Set0' and the set containing only the members of `Xs'.
-
+ %
:- pred set_unordlist__insert_list(set_unordlist(T)::in, list(T)::in,
set_unordlist(T)::out) is det.
@@ -122,7 +122,7 @@
% relative complement of `Set0' and the set containing only `X', i.e.
% if `Set' is the set which contains all the elements of `Set0'
% except `X'.
-
+ %
:- pred set_unordlist__delete(set_unordlist(T), T, set_unordlist(T)).
:- mode set_unordlist__delete(di, in, uo) is det.
:- mode set_unordlist__delete(in, in, out) is det.
@@ -132,7 +132,7 @@
% `set_unordlist__delete_list(Set0, Xs, Set)' is true iff `Set' is the
% relative complement of `Set0' and the set containing only the members
% of `Xs'.
-
+ %
:- pred set_unordlist__delete_list(set_unordlist(T)::in, list(T)::in,
set_unordlist(T)::out) is det.
@@ -143,7 +143,7 @@
% and `Set' is the relative complement of `Set0' and the set
% containing only `X', i.e. if `Set' is the set which contains
% all the elements of `Set0' except `X'.
-
+ %
:- pred set_unordlist__remove(set_unordlist(T)::in, T::in,
set_unordlist(T)::out) is semidet.
@@ -151,21 +151,21 @@
% contain any duplicates, `Set0' contains every member of `Xs',
% and `Set' is the relative complement of `Set0' and the set
% containing only the members of `Xs'.
-
+ %
:- pred set_unordlist__remove_list(set_unordlist(T)::in, list(T)::in,
set_unordlist(T)::out) is semidet.
% `set_unordlist__remove_least(Set0, X, Set)' is true iff `X' is the
% least element in `Set0', and `Set' is the set which contains all the
% elements of `Set0' except `X'.
-
+ %
:- pred set_unordlist__remove_least(set_unordlist(T)::in, T::out,
set_unordlist(T)::out) is semidet.
% `set_unordlist_union(SetA, SetB, Set)' is true iff `Set' is the union
% of `SetA' and `SetB'. If the sets are known to be of different
% sizes, then for efficiency make `SetA' the larger of the two.
-
+ %
:- pred set_unordlist__union(set_unordlist(T)::in, set_unordlist(T)::in,
set_unordlist(T)::out) is det.
@@ -174,12 +174,12 @@
% `set_unordlist__union_list(A) = B' is true iff `B' is the union of
% all the sets in `A'
-
+ %
:- func set_unordlist__union_list(list(set_unordlist(T))) = set_unordlist(T).
% `set_unordlist__power_union(A, B)' is true iff `B' is the union of
% all the sets in `A'
-
+ %
:- pred set_unordlist__power_union(set_unordlist(set_unordlist(T))::in,
set_unordlist(T)::out) is det.
@@ -188,7 +188,7 @@
% `set_unordlist__intersect(SetA, SetB, Set)' is true iff `Set' is the
% intersection of `SetA' and `SetB'.
-
+ %
:- pred set_unordlist__intersect(set_unordlist(T)::in, set_unordlist(T)::in,
set_unordlist(T)::out) is det.
@@ -197,7 +197,7 @@
% `set_unordlist__power_intersect(A, B)' is true iff `B' is the
% intersection of all the sets in `A'
-
+ %
:- pred set_unordlist__power_intersect(set_unordlist(set_unordlist(T))::in,
set_unordlist(T)::out) is det.
@@ -206,14 +206,14 @@
% `set_unordlist__intersect_list(A, B)' is true iff `B' is the
% intersection of all the sets in `A'
-
+ %
:- func set_unordlist__intersect_list(list(set_unordlist(T)))
= set_unordlist(T).
% `set_unordlist__difference(SetA, SetB, Set)' is true iff `Set' is the
% set containing all the elements of `SetA' except those that
% occur in `SetB'
-
+ %
:- pred set_unordlist__difference(set_unordlist(T)::in, set_unordlist(T)::in,
set_unordlist(T)::out) is det.
@@ -232,6 +232,7 @@
% set_unordlist__divide(Pred, Set, TruePart, FalsePart):
% TruePart consists of those elements of Set for which Pred succeeds;
% FalsePart consists of those elements of Set for which Pred fails.
+ %
:- pred set_unordlist__divide(pred(T1), set_unordlist(T1), set_unordlist(T1),
set_unordlist(T1)).
:- mode set_unordlist__divide(pred(in) is semidet, in, out, out) is det.
Index: library/sparse_bitset.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/sparse_bitset.m,v
retrieving revision 1.21
diff -u -r1.21 sparse_bitset.m
--- library/sparse_bitset.m 15 Dec 2004 06:57:41 -0000 1.21
+++ library/sparse_bitset.m 19 Jan 2005 03:55:56 -0000
@@ -59,75 +59,77 @@
% `equal(SetA, SetB' is true iff `SetA' and `SetB'
% contain the same elements.
% Takes O(min(rep_size(SetA), rep_size(SetB))) time.
-:- pred equal(sparse_bitset(T), sparse_bitset(T)).
-:- mode equal(in, in) is semidet.
+ %
+:- pred equal(sparse_bitset(T)::in, sparse_bitset(T)::in) is semidet.
% `list_to_set(List)' returns a set
% containing only the members of `List'.
% In the worst case this will take O(length(List)^2) time
% and space. If the elements of the list are closely
% grouped, it will be closer to O(length(List)).
+ %
:- func list_to_set(list(T)) = sparse_bitset(T) <= enum(T).
-
-:- pred list_to_set(list(T), sparse_bitset(T)) <= enum(T).
-:- mode list_to_set(in, out) is det.
+:- pred list_to_set(list(T)::in, sparse_bitset(T)::out) is det <= enum(T).
% `sorted_list_to_set(List)' returns a set containing
% only the members of `List'.
% `List' must be sorted.
% Takes O(length(List)) time and space.
+ %
:- func sorted_list_to_set(list(T)) = sparse_bitset(T) <= enum(T).
-
-:- pred sorted_list_to_set(list(T), sparse_bitset(T)) <= enum(T).
-:- mode sorted_list_to_set(in, out) is det.
+:- pred sorted_list_to_set(list(T)::in, sparse_bitset(T)::out)
+ is det <= enum(T).
% `sorted_list_to_set(Set)' returns a bitset containing
% only the members of `Set'.
% `List' must be sorted.
% Takes O(card(Set)) time and space.
+ %
:- func from_set(set.set(T)) = sparse_bitset(T) <= enum(T).
% `to_sorted_list(Set)' returns a list
% containing all the members of `Set', in sorted order.
% Takes O(card(Set)) time and space.
+ %
:- func to_sorted_list(sparse_bitset(T)) = list(T) <= enum(T).
-
-:- pred to_sorted_list(sparse_bitset(T), list(T)) <= enum(T).
-:- mode to_sorted_list(in, out) is det.
+:- pred to_sorted_list(sparse_bitset(T)::in, list(T)::out) is det <= enum(T).
% `to_sorted_list(Set)' returns a set.set containing all
% the members of `Set', in sorted order.
% Takes O(card(Set)) time and space.
+ %
:- func to_set(sparse_bitset(T)) = set.set(T) <= enum(T).
% `make_singleton_set(Elem)' returns a set
% containing just the single element `Elem'.
+ %
:- func make_singleton_set(T) = sparse_bitset(T) <= enum(T).
% Note: set.m contains the reverse mode of this predicate,
% but it is difficult to implement both modes using
% the representation in this module.
-:- pred singleton_set(sparse_bitset(T), T) <= enum(T).
-:- mode singleton_set(out, in) is det.
+ %
+:- pred singleton_set(sparse_bitset(T)::out, T::in) is det <= enum(T).
% `subset(Subset, Set)' is true iff `Subset' is a subset of `Set'.
% Same as `intersect(Set, Subset, Subset)', but may be more efficient.
-:- pred subset(sparse_bitset(T), sparse_bitset(T)).
-:- mode subset(in, in) is semidet.
+ %
+:- pred subset(sparse_bitset(T)::in, sparse_bitset(T)::in) is semidet.
% `superset(Superset, Set)' is true iff `Superset' is a
% superset of `Set'.
% Same as `intersect(Superset, Set, Set)', but may be more efficient.
-:- pred superset(sparse_bitset(T), sparse_bitset(T)).
-:- mode superset(in, in) is semidet.
+ %
+:- pred superset(sparse_bitset(T)::in, sparse_bitset(T)::in) is semidet.
% `contains(Set, X)' is true iff `X' is a member of `Set'.
% Takes O(rep_size(Set)) time.
-:- pred contains(sparse_bitset(T), T) <= enum(T).
-:- mode contains(in, in) is semidet.
+ %
+:- pred contains(sparse_bitset(T)::in, T::in) is semidet <= enum(T).
% `member(Set, X)' is true iff `X' is a member of `Set'.
% Takes O(rep_size(Set)) time.
+ %
:- pred member(T, sparse_bitset(T)) <= enum(T).
:- mode member(in, in) is semidet.
:- mode member(out, in) is nondet.
@@ -135,44 +137,44 @@
% `insert(Set, X)' returns the union
% of `Set' and the set containing only `X'.
% Takes O(rep_size(Set)) time and space.
+ %
:- func insert(sparse_bitset(T), T) = sparse_bitset(T) <= enum(T).
-
-:- pred insert(sparse_bitset(T), T, sparse_bitset(T)) <= enum(T).
-:- mode insert(in, in, out) is det.
+:- pred insert(sparse_bitset(T)::in, T::in, sparse_bitset(T)::out)
+ is det <= enum(T).
% `insert_list(Set, X)' returns the union of `Set' and the set
% containing only the members of `X'.
% Same as `union(Set, list_to_set(X))', but may be more efficient.
+ %
:- func insert_list(sparse_bitset(T), list(T)) = sparse_bitset(T) <= enum(T).
-
-:- pred insert_list(sparse_bitset(T), list(T), sparse_bitset(T)) <= enum(T).
-:- mode insert_list(in, in, out) is det.
+:- pred insert_list(sparse_bitset(T)::in, list(T)::in, sparse_bitset(T)::out)
+ is det <= enum(T).
% `delete(Set, X)' returns the difference
% of `Set' and the set containing only `X'.
% Takes O(rep_size(Set)) time and space.
+ %
:- func delete(sparse_bitset(T), T) = sparse_bitset(T) <= enum(T).
-
-:- pred delete(sparse_bitset(T), T, sparse_bitset(T)) <= enum(T).
-:- mode delete(in, in, out) is det.
+:- pred delete(sparse_bitset(T)::in, T::in, sparse_bitset(T)::out)
+ is det <= enum(T).
% `delete_list(Set, X)' returns the difference of `Set' and the set
% containing only the members of `X'.
% Same as `difference(Set, list_to_set(X))', but may be more efficient.
+ %
:- func delete_list(sparse_bitset(T), list(T)) = sparse_bitset(T) <= enum(T).
-
-:- pred delete_list(sparse_bitset(T), list(T), sparse_bitset(T)) <= enum(T).
-:- mode delete_list(in, in, out) is det.
+:- pred delete_list(sparse_bitset(T)::in, list(T)::in, sparse_bitset(T)::out)
+ is det <= enum(T).
% `remove(Set, X)' returns the difference
% of `Set' and the set containing only `X',
% failing if `Set' does not contain `X'.
% Takes O(rep_size(Set)) time and space.
-:- func remove(sparse_bitset(T), T) = sparse_bitset(T) <= enum(T).
-:- mode remove(in, in) = out is semidet.
-
-:- pred remove(sparse_bitset(T), T, sparse_bitset(T)) <= enum(T).
-:- mode remove(in, in, out) is semidet.
+ %
+:- func remove(sparse_bitset(T)::in, T::in) = (sparse_bitset(T)::out)
+ is semidet <= enum(T).
+:- pred remove(sparse_bitset(T)::in, T::in, sparse_bitset(T)::out)
+ is semidet <= enum(T).
% `remove_list(Set, X)' returns the difference of `Set'
% and the set containing all the elements of `X',
@@ -180,65 +182,67 @@
% Same as
% `subset(list_to_set(X), Set), difference(Set, list_to_set(X))',
% but may be more efficient.
-:- func remove_list(sparse_bitset(T), list(T)) = sparse_bitset(T) <= enum(T).
-:- mode remove_list(in, in) = out is semidet.
-
-:- pred remove_list(sparse_bitset(T), list(T), sparse_bitset(T)) <= enum(T).
-:- mode remove_list(in, in, out) is semidet.
+ %
+:- func remove_list(sparse_bitset(T)::in, list(T)::in) = (sparse_bitset(T)::out)
+ is semidet <= enum(T).
+:- pred remove_list(sparse_bitset(T)::in, list(T)::in, sparse_bitset(T)::out)
+ is semidet <= enum(T).
% `remove_leq(Set, X)' returns `Set' with all elements less than
% or equal to `X' removed. In other words, it returns the set
% containing all the elements of `Set' which are greater than `X'.
+ %
:- func remove_leq(sparse_bitset(T), T) = sparse_bitset(T) <= enum(T).
-
-:- pred remove_leq(sparse_bitset(T), T, sparse_bitset(T)) <= enum(T).
-:- mode remove_leq(in, in, out) is det.
+:- pred remove_leq(sparse_bitset(T)::in, T::in, sparse_bitset(T)::out)
+ is det <= enum(T).
% `remove_gt(Set, X)' returns `Set' with all elements greater
% than `X' removed. In other words, it returns the set containing
% all the elements of `Set' which are less than or equal to `X'.
+ %
:- func remove_gt(sparse_bitset(T), T) = sparse_bitset(T) <= enum(T).
-
-:- pred remove_gt(sparse_bitset(T), T, sparse_bitset(T)) <= enum(T).
-:- mode remove_gt(in, in, out) is det.
+:- pred remove_gt(sparse_bitset(T)::in, T::in, sparse_bitset(T)::out)
+ is det <= enum(T).
% `remove_least(Set0, X, Set)' is true iff `X' is the
% least element in `Set0', and `Set' is the set which
% contains all the elements of `Set0' except `X'.
% Takes O(1) time and space.
-:- pred remove_least(sparse_bitset(T), T, sparse_bitset(T)) <= enum(T).
-:- mode remove_least(in, out, out) is semidet.
+ %
+:- pred remove_least(sparse_bitset(T)::in, T::out, sparse_bitset(T)::out)
+ is semidet <= enum(T).
% `union(SetA, SetB)' returns the union of `SetA' and `SetB'.
% The efficiency of the union operation is not sensitive
% to the argument ordering.
% Takes O(rep_size(SetA) + rep_size(SetB)) time and space.
+ %
:- func union(sparse_bitset(T), sparse_bitset(T)) = sparse_bitset(T).
-
-:- pred union(sparse_bitset(T), sparse_bitset(T), sparse_bitset(T)).
-:- mode union(in, in, out) is det.
+:- pred union(sparse_bitset(T)::in, sparse_bitset(T)::in,
+ sparse_bitset(T)::out) is det.
% `intersect(SetA, SetB)' returns the intersection of
% `SetA' and `SetB'. The efficiency of the intersection
% operation is not sensitive to the argument ordering.
% Takes O(rep_size(SetA) + rep_size(SetB)) time and
% O(min(rep_size(SetA)), rep_size(SetB)) space.
+ %
:- func intersect(sparse_bitset(T), sparse_bitset(T)) = sparse_bitset(T).
-
-:- pred intersect(sparse_bitset(T), sparse_bitset(T), sparse_bitset(T)).
-:- mode intersect(in, in, out) is det.
+:- pred intersect(sparse_bitset(T)::in, sparse_bitset(T)::in,
+ sparse_bitset(T)::out) is det.
% `difference(SetA, SetB)' returns the set containing all the
% elements of `SetA' except those that occur in `SetB'.
% Takes O(rep_size(SetA) + rep_size(SetB)) time and
% O(rep_size(SetA)) space.
+ %
:- func difference(sparse_bitset(T), sparse_bitset(T)) = sparse_bitset(T).
-
-:- pred difference(sparse_bitset(T), sparse_bitset(T), sparse_bitset(T)).
-:- mode difference(in, in, out) is det.
+:- pred difference(sparse_bitset(T)::in, sparse_bitset(T)::in,
+ sparse_bitset(T)::out) is det.
% `count(Set)' returns the number of elements in `Set'.
% Takes O(card(Set)) time.
+ %
:- func count(sparse_bitset(T)) = int <= enum(T).
% `foldl(Func, Set, Start)' calls Func with each element
@@ -246,6 +250,7 @@
% (with the initial value of `Start'), and returns
% the final value.
% Takes O(card(Set)) time.
+ %
:- func foldl(func(T, U) = U, sparse_bitset(T), U) = U <= enum(T).
:- pred foldl(pred(T, U, U), sparse_bitset(T), U, U) <= enum(T).
@@ -261,6 +266,7 @@
% (with the initial value of `Start'), and returns
% the final value.
% Takes O(card(Set)) time.
+ %
:- func foldr(func(T, U) = U, sparse_bitset(T), U) = U <= enum(T).
:- pred foldr(pred(T, U, U), sparse_bitset(T), U, U) <= enum(T).
@@ -274,10 +280,12 @@
% `filter(Pred, Set)' removes those elements from `Set' for which
% `Pred' fails. In other words, it returns the set consisting of those
% elements of `Set' for which `Pred' succeeds.
+ %
:- func filter(pred(T), sparse_bitset(T)) = sparse_bitset(T) <= enum(T).
:- mode filter(pred(in) is semidet, in) = out is det.
%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
:- implementation.
Index: library/stack.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/stack.m,v
retrieving revision 1.18
diff -u -r1.18 stack.m
--- library/stack.m 12 Nov 2000 08:51:37 -0000 1.18
+++ library/stack.m 18 Jan 2005 12:52:45 -0000
@@ -20,78 +20,64 @@
:- type stack(_T).
% `stack__init(Stack)' is true iff `Stack' is an empty stack.
-
-:- pred stack__init(stack(_T)).
-:- mode stack__init(out) is det.
-
+ %
+:- pred stack__init(stack(_T)::out) is det.
:- func stack__init = stack(T).
% `stack__is_empty(Stack)' is true iff `Stack' is an empty stack.
-
-:- pred stack__is_empty(stack(_T)).
-:- mode stack__is_empty(in) is semidet.
+ %
+:- pred stack__is_empty(stack(_T)::in) is semidet.
% `stack__is_full(Stack)' is intended to be true iff `Stack'
% is a stack whose capacity is exhausted. This implementation
% allows arbitrary-sized stacks, so stack__is_full always fails.
-
-:- pred stack__is_full(stack(_T)).
-:- mode stack__is_full(in) is semidet.
+ %
+:- pred stack__is_full(stack(_T)::in) is semidet.
% `stack__push(Stack0, Elem, Stack)' is true iff `Stack' is
% the stack which results from pushing `Elem' onto the top
% of `Stack0'.
-
-:- pred stack__push(stack(T), T, stack(T)).
-:- mode stack__push(in, in, out) is det.
-
+ %
+:- pred stack__push(stack(T)::in, T::in, stack(T)::out) is det.
:- func stack__push(stack(T), T) = stack(T).
% `stack__push_list(Stack0, Elems, Stack)' is true iff `Stack'
% is the stack which results from pushing the elements of the
% list `Elems' onto the top of `Stack0'.
-
-:- pred stack__push_list(stack(T), list(T), stack(T)).
-:- mode stack__push_list(in, in, out) is det.
-
+ %
+:- pred stack__push_list(stack(T)::in, list(T)::in, stack(T)::out) is det.
:- func stack__push_list(stack(T), list(T)) = stack(T).
% `stack__top(Stack, Elem)' is true iff `Stack' is a non-empty
% stack whose top element is `Elem'.
-
-:- pred stack__top(stack(T), T).
-:- mode stack__top(in, out) is semidet.
+ %
+:- pred stack__top(stack(T)::in, T::out) is semidet.
% `stack__top_det' is like `stack__top' except that it will
% call error/1 rather than failing if given an empty stack.
-
-:- pred stack__top_det(stack(T), T).
-:- mode stack__top_det(in, out) is det.
-
+ %
+:- pred stack__top_det(stack(T)::in, T::out) is det.
:- func stack__top_det(stack(T)) = T.
% `stack__pop(Stack0, Elem, Stack)' is true iff `Stack0' is
% a non-empty stack whose top element is `Elem', and `Stack'
% the stack which results from popping `Elem' off `Stack0'.
-
-:- pred stack__pop(stack(T), T, stack(T)).
-:- mode stack__pop(in, out, out) is semidet.
+ %
+:- pred stack__pop(stack(T)::in, T::out, stack(T)::out) is semidet.
% `stack__pop_det' is like `stack__pop' except that it will
% call error/1 rather than failing if given an empty stack.
-
-:- pred stack__pop_det(stack(T), T, stack(T)).
-:- mode stack__pop_det(in, out, out) is det.
+ %
+:- pred stack__pop_det(stack(T)::in, T::out, stack(T)::out) is det.
% `stack__depth(Stack, Depth)' is true iff `Stack' is a stack
% containing `Depth' elements.
-
-:- pred stack__depth(stack(_T), int).
-:- mode stack__depth(in, out) is det.
-
+ %
+:- pred stack__depth(stack(_T)::in, int::out) is det.
:- func stack__depth(stack(T)) = int.
%--------------------------------------------------------------------------%
+%--------------------------------------------------------------------------%
:- implementation.
Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.296
diff -u -r1.296 std_util.m
--- library/std_util.m 14 Dec 2004 01:07:20 -0000 1.296
+++ library/std_util.m 18 Jan 2005 10:54:01 -0000
@@ -22,8 +22,9 @@
:- import_module type_desc.
%-----------------------------------------------------------------------------%
-
+%
% The universal type `univ'.
+%
% An object of type `univ' can hold the type and value of an object of any
% other type.
@@ -65,8 +66,7 @@
% the same as the forwards mode of univ_to_type, but
% abort if univ_to_type fails.
%
-:- pred det_univ_to_type(univ, T).
-:- mode det_univ_to_type(in, out) is det.
+:- pred det_univ_to_type(univ::in, T::out) is det.
% univ_type(Univ):
% returns the type_desc for the type stored in `Univ'.
@@ -78,8 +78,9 @@
:- some [T] func univ_value(univ) = T.
%-----------------------------------------------------------------------------%
-
+%
% The "maybe" type.
+%
:- type maybe(T) ---> no ; yes(T).
:- inst maybe(I) ---> no ; yes(I).
@@ -104,6 +105,7 @@
% 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.
@@ -111,6 +113,7 @@
% 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) :-
@@ -122,6 +125,7 @@
:- 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,
@@ -130,16 +134,18 @@
in, out, in, out, di, uo) is det.
%-----------------------------------------------------------------------------%
-
+%
% The "unit" type - stores no information at all.
+%
:- type unit ---> unit.
:- type unit(T) ---> unit1.
%-----------------------------------------------------------------------------%
-
+%
% The "pair" type. Useful for many purposes.
+%
:- type pair(T1, T2) ---> (T1 - T2).
:- type pair(T) == pair(T,T).
@@ -147,10 +153,12 @@
:- 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.
@@ -299,21 +307,25 @@
is cc_multi.
%-----------------------------------------------------------------------------%
-
- % General purpose higher-order programming constructs.
+%
+% 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)
+ % 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.
@@ -341,8 +353,7 @@
% Odds = list__filter(odd, Xs)
% Evens = list__filter(isnt(odd), Xs)
%
-:- pred isnt(pred(T), T).
-:- mode isnt(pred(in) is semidet, in) is semidet.
+:- pred isnt(pred(T)::(pred(in) is semidet), T::in) is semidet.
%-----------------------------------------------------------------------------%
@@ -369,13 +380,13 @@
% provide access to type information.
% A type_desc represents a type, e.g. `list(int)'.
% A type_ctor_desc represents a type constructor, e.g. `list/1'.
-
+ %
:- type type_desc == type_desc__type_desc.
:- type type_ctor_desc == type_desc__type_ctor_desc.
% Type_info and type_ctor_info are the old names for type_desc and
% type_ctor_desc. They should not be used by new software.
-
+ %
:- type type_info == type_desc__type_desc.
:- type type_ctor_info == type_desc__type_ctor_desc.
@@ -391,13 +402,13 @@
% The function type_of/1 returns a representation of the type
% of its argument.
%
-:- func type_of(T) = type_desc__type_desc.
-:- mode type_of(unused) = out is det.
+:- func type_of(T::unused) = (type_desc__type_desc::out) is det.
% The predicate has_type/2 is basically an existentially typed
% inverse to the function type_of/1. It constrains the type
% of the first argument to be the type represented by the
% second argument.
+ %
:- some [T] pred has_type(T::unused, type_desc__type_desc::in) is det.
% type_name(Type) returns the name of the specified type
@@ -427,9 +438,9 @@
% (If you don't want them expanded, you can use the reverse mode
% of make_type/2 instead.)
%
-:- pred type_ctor_and_args(type_desc__type_desc, type_desc__type_ctor_desc,
- list(type_desc__type_desc)).
-:- mode type_ctor_and_args(in, out, out) is det.
+:- pred type_ctor_and_args(type_desc__type_desc::in,
+ type_desc__type_ctor_desc::out, list(type_desc__type_desc)::out)
+ is det.
% type_ctor(Type) = TypeCtor :-
% type_ctor_and_args(Type, TypeCtor, _).
@@ -542,6 +553,7 @@
% for the specified type of the function symbol that is in position I
% in lexicographic order. Fails if the type is not a discriminated
% union type, or if I is out of range.
+ %
:- pred get_functor_ordinal(type_desc__type_desc::in, int::in, int::out)
is semidet.
@@ -555,12 +567,12 @@
% functor, or if the types of the arguments do not match
% the expected argument types of that functor.
%
-:- func construct(type_desc__type_desc, int, list(univ)) = univ.
-:- mode construct(in, in, in) = out is semidet.
+:- func construct(type_desc__type_desc, int, list(univ)) = univ is semidet.
% construct_tuple(Args) = Term
%
% Returns a tuple whose arguments are given by Args.
+ %
:- func construct_tuple(list(univ)) = univ.
%-----------------------------------------------------------------------------%
@@ -718,6 +730,7 @@
maybe({string, int, list(univ)})::out) is cc_multi.
%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
:- implementation.
:- interface.
Index: library/store.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/store.m,v
retrieving revision 1.45
diff -u -r1.45 store.m
--- library/store.m 15 Mar 2004 06:50:17 -0000 1.45
+++ library/store.m 18 Jan 2005 10:56:50 -0000
@@ -56,8 +56,9 @@
:- type io_mutvar(T) == generic_mutvar(T, io__state).
:- type store_mutvar(T, S) == generic_mutvar(T, store(S)).
- % create a new mutable variable,
- % initialized with the specified value
+ % Create a new mutable variable,
+ % initialized with the specified value.
+ %
:- pred store__new_mutvar(T::in, generic_mutvar(T, S)::out, S::di, S::uo)
is det <= store(S).
@@ -65,14 +66,17 @@
% is equivalent to the sequence
% get_mutvar(OldMutvar, Value, S0, S1),
% new_mutvar(NewMutvar, Value, S1, S )
+ %
:- pred store__copy_mutvar(generic_mutvar(T, S)::in, generic_mutvar(T, S)::out,
S::di, S::uo) is det <= store(S).
- % lookup the value stored in a given mutable variable
+ % Lookup the value stored in a given mutable variable.
+ %
:- pred store__get_mutvar(generic_mutvar(T, S)::in, T::out,
S::di, S::uo) is det <= store(S).
- % replace the value stored in a given mutable variable
+ % Replace the value stored in a given mutable variable.
+ %
:- pred store__set_mutvar(generic_mutvar(T, S)::in, T::in,
S::di, S::uo) is det <= store(S).
@@ -102,7 +106,7 @@
%-----------------------------------------------------------------------------%
%
-% references
+% References
%
% generic_ref(T, S):
@@ -119,12 +123,14 @@
% of the representation of that value.
% It does however allocate one cell to hold the reference;
% you can use new_arg_ref to avoid that.)
+ %
:- pred store__new_ref(T::di, generic_ref(T, S)::out,
S::di, S::uo) is det <= store(S).
% ref_functor(Ref, Functor, Arity):
% Given a reference to a term, return the functor and arity
% of that term.
+ %
:- pred store__ref_functor(generic_ref(T, S)::in, string::out, int::out,
S::di, S::uo) is det <= store(S).
@@ -135,6 +141,7 @@
% (argument numbers start from zero).
% It is an error if the argument number is out of range,
% or if the argument reference has the wrong type.
+ %
:- pred store__arg_ref(generic_ref(T, S)::in, int::in,
generic_ref(ArgT, S)::out, S::di, S::uo) is det <= store(S).
@@ -144,6 +151,7 @@
% except that it is more efficient.
% It is an error if the argument number is out of range,
% or if the argument reference has the wrong type.
+ %
:- pred store__new_arg_ref(T::di, int::in, generic_ref(ArgT, S)::out,
S::di, S::uo) is det <= store(S).
@@ -153,6 +161,7 @@
% a reference to another term (ValueRef),
% update the store so that the term referred to by Ref
% is replaced with the term referenced by ValueRef.
+ %
:- pred store__set_ref(generic_ref(T, S)::in, generic_ref(T, S)::in,
S::di, S::uo) is det <= store(S).
@@ -161,6 +170,7 @@
% Given a reference to a term (Ref), and a value (Value),
% update the store so that the term referred to by Ref
% is replaced with Value.
+ %
:- pred store__set_ref_value(generic_ref(T, S)::in, T::di,
S::di, S::uo) is det <= store(S).
@@ -169,11 +179,13 @@
% be inefficient if used to return large terms; it
% is most efficient with atomic terms.
% XXX current implementation buggy (does shallow copy)
+ %
:- pred store__copy_ref_value(generic_ref(T, S)::in, T::uo,
S::di, S::uo) is det <= store(S).
% Same as above, but without making a copy.
% Destroys the store.
+ %
:- pred store__extract_ref_value(S::di, generic_ref(T, S)::in, T::out)
is det <= store(S).
Index: library/string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.224
diff -u -r1.224 string.m
--- library/string.m 11 Jan 2005 06:06:14 -0000 1.224
+++ library/string.m 18 Jan 2005 11:11:10 -0000
@@ -25,6 +25,7 @@
% Determine the length of a string.
% An empty string has length zero.
+ %
:- func string__length(string) = int.
:- mode string__length(in) = uo is det.
:- pred string__length(string, int).
@@ -32,6 +33,7 @@
:- mode string__length(ui, uo) is det.
% Append two strings together.
+ %
:- func string__append(string, string) = string.
:- mode string__append(in, in) = uo is det.
@@ -55,50 +57,55 @@
% string__remove_suffix(String, Suffix, Prefix):
% The same as string__append(Prefix, Suffix, String) except that
% this is semidet whereas string__append(out, in, in) is nondet.
-:- pred string__remove_suffix(string, string, string).
-:- mode string__remove_suffix(in, in, out) is semidet.
+ %
+:- pred string__remove_suffix(string::in, string::in, string::out) is semidet.
% string__prefix(String, Prefix) is true iff Prefix is a
% prefix of String. Same as string__append(Prefix, _, String).
+ %
:- pred string__prefix(string, string).
:- mode string__prefix(in, in) is semidet.
:- mode string__prefix(in, out) is multi.
% string__suffix(String, Suffix) is true iff Suffix is a
% suffix of String. Same as string__append(_, Suffix, String).
+ %
:- pred string__suffix(string, string).
:- mode string__suffix(in, in) is semidet.
:- mode string__suffix(in, out) is multi.
+ % string__string(X): Returns a canonicalized string
+ % representation of the value X using the standard Mercury operators.
+ %
:- func string__string(T) = string.
- % string__string(X): Returns a canonicalized string representation of
- % the value X using the standard Mercury operators.
-:- func string__string(ops__table, T) = string.
- %
% As above, but using the supplied table of operators.
+ %
+:- func string__string(ops__table, T) = string.
+ % string__string(NonCanon, OpsTable, X, String)
+ %
+ % As above, but the caller specifies what behaviour should
+ % occur for non-canonical terms (i.e. terms where multiple
+ % representations may compare as equal):
+ % - `do_not_allow' will throw an exception if (any subterm of)
+ % the argument is not canonical;
+ % - `canonicalize' will substitute a string indicating the
+ % presence of a non-canonical subterm;
+ % - `include_details_cc' will show the structure of any
+ % non-canonical subterms, but can only be called from a
+ % committed choice context.
+ %
:- pred string__string(deconstruct__noncanon_handling, ops__table, T, string).
:- mode string__string(in(do_not_allow), in, in, out) is det.
:- mode string__string(in(canonicalize), in, in, out) is det.
:- mode string__string(in(include_details_cc), in, in, out) is cc_multi.
:- mode string__string(in, in, in, out) is cc_multi.
-% string__string(NonCanon, OpsTable, X, String)
-%
-% As above, but the caller specifies what behaviour should
-% occur for non-canonical terms (i.e. terms where multiple
-% representations may compare as equal):
-% - `do_not_allow' will throw an exception if (any subterm of)
-% the argument is not canonical;
-% - `canonicalize' will substitute a string indicating the
-% presence of a non-canonical subterm;
-% - `include_details_cc' will show the structure of any
-% non-canonical subterms, but can only be called from a
-% committed choice context.
-
+
% string__char_to_string(Char, String).
% Converts a character (single-character atom) to a string
% or vice versa.
+ %
:- func string__char_to_string(char) = string.
:- mode string__char_to_string(in) = uo is det.
:- pred string__char_to_string(char, string).
@@ -106,6 +113,7 @@
:- mode string__char_to_string(out, in) is semidet.
% Convert an integer to a string.
+ %
:- func string__int_to_string(int) = string.
:- mode string__int_to_string(in) = uo is det.
:- pred string__int_to_string(int, string).
@@ -113,6 +121,7 @@
% string__int_to_base_string(Int, Base, String):
% Convert an integer to a string in a given Base (between 2 and 36).
+ %
:- func string__int_to_base_string(int, int) = string.
:- mode string__int_to_base_string(in, in) = uo is det.
:- pred string__int_to_base_string(int, int, string).
@@ -125,6 +134,7 @@
% where p = floor(mantissa_digits * log2(base_radix) / log2(10)).
% The precision chosen from this range will be such to allow a
% successful decimal -> binary conversion of the float.
+ %
:- func string__float_to_string(float) = string.
:- mode string__float_to_string(in) = uo is det.
:- pred string__float_to_string(float, string).
@@ -139,6 +149,7 @@
% Repeated use of string__first_char to iterate
% over a string will result in very poor performance.
% Use string__foldl or string__to_char_list instead.
+ %
:- pred string__first_char(string, char, string).
:- mode string__first_char(in, in, in) is semidet. % implied
:- mode string__first_char(in, uo, in) is semidet. % implied
@@ -150,18 +161,21 @@
% string__replace replaces the first occurrence of Search in String0
% with Replace to give String. It fails if Search does not occur
% in String0.
-:- pred string__replace(string, string, string, string).
-:- mode string__replace(in, in, in, uo) is semidet.
+ %
+:- pred string__replace(string::in, string::in, string::in, string::uo)
+ is semidet.
% string__replace_all(String0, Search, Replace, String):
% string__replace_all replaces any occurrences of Search in
% String0 with Replace to give String.
+ %
:- func string__replace_all(string, string, string) = string.
:- mode string__replace_all(in, in, in) = uo is det.
:- pred string__replace_all(string, string, string, string).
:- mode string__replace_all(in, in, in, uo) is det.
% Converts a string to lowercase.
+ %
:- func string__to_lower(string) = string.
:- mode string__to_lower(in) = uo is det.
:- pred string__to_lower(string, string).
@@ -169,6 +183,7 @@
:- mode string__to_lower(in, in) is semidet. % implied
% Converts a string to uppercase.
+ %
:- func string__to_upper(string) = string.
:- mode string__to_upper(in) = uo is det.
:- pred string__to_upper(string, string).
@@ -176,20 +191,24 @@
:- mode string__to_upper(in, in) is semidet. % implied
% Convert the first character (if any) of a string to uppercase.
+ %
:- func string__capitalize_first(string) = string.
:- pred string__capitalize_first(string::in, string::out) is det.
% Convert the first character (if any) of a string to lowercase.
+ %
:- func string__uncapitalize_first(string) = string.
:- pred string__uncapitalize_first(string::in, string::out) is det.
% Convert the string to a list of characters.
+ %
:- func string__to_char_list(string) = list(char).
:- pred string__to_char_list(string, list(char)).
:- mode string__to_char_list(in, out) is det.
:- mode string__to_char_list(uo, in) is det.
% Convert a list of characters to a string.
+ %
:- func string__from_char_list(list(char)) = string.
:- mode string__from_char_list(in) = uo is det.
:- pred string__from_char_list(list(char), string).
@@ -198,6 +217,7 @@
% Same as string__from_char_list, except that it reverses the order
% of the characters.
+ %
:- func string__from_rev_char_list(list(char)) = string.
:- mode string__from_rev_char_list(in) = uo is det.
:- pred string__from_rev_char_list(list(char), string).
@@ -205,6 +225,7 @@
% Converts a signed base 10 string to an int; throws an exception
% if the string argument does not match the regexp [+-]?[0-9]+
+ %
:- func string__det_to_int(string) = int.
% Convert a string to an int. The string must contain only digits,
@@ -217,11 +238,13 @@
% optionally preceded by a plus or minus sign. For bases > 10,
% digits 10 to 35 are represented by the letters A-Z or a-z. If
% the string does not match this syntax, the predicate fails.
+ %
:- pred string__base_string_to_int(int::in, string::in, int::out) is semidet.
% Converts a signed base N string to an int; throws an exception
% if the string argument is not precisely an optional sign followed
% by a non-empty string of base N digits.
+ %
:- func string__det_base_string_to_int(int, string) = int.
% Convert a string to a float. Throws an exception if the string
@@ -231,54 +254,65 @@
% Convert a string to a float. If the string is not a syntactically
% correct float literal, string__to_float fails.
+ %
:- pred string__to_float(string::in, float::out) is semidet.
% True if string contains only alphabetic characters (letters).
+ %
:- pred string__is_alpha(string::in) is semidet.
% True if string contains only alphabetic characters and underscores.
+ %
:- pred string__is_alpha_or_underscore(string::in) is semidet.
% True if string contains only letters, digits, and underscores.
+ %
:- pred string__is_alnum_or_underscore(string::in) is semidet.
% string__pad_left(String0, PadChar, Width, String):
% Insert `PadChar's at the left of `String0' until it is at least
% as long as `Width', giving `String'.
+ %
:- func string__pad_left(string, char, int) = string.
:- pred string__pad_left(string::in, char::in, int::in, string::out) is det.
% string__pad_right(String0, PadChar, Width, String):
% Insert `PadChar's at the right of `String0' until it is at least
% as long as `Width', giving `String'.
+ %
:- func string__pad_right(string, char, int) = string.
:- pred string__pad_right(string::in, char::in, int::in, string::out) is det.
% string__duplicate_char(Char, Count, String):
% Construct a string consisting of `Count' occurrences of `Char'
% in sequence.
+ %
:- func string__duplicate_char(char::in, int::in) = (string::uo) is det.
:- pred string__duplicate_char(char::in, int::in, string::uo) is det.
% string__contains_char(String, Char):
% Succeed if `Char' occurs in `String'.
+ %
:- pred string__contains_char(string::in, char::in) is semidet.
% string__index(String, Index, Char):
% `Char' is the (`Index' + 1)-th character of `String'.
% Fails if `Index' is out of range (negative, or greater than or
% equal to the length of `String').
+ %
:- pred string__index(string::in, int::in, char::uo) is semidet.
% string__index_det(String, Index, Char):
% `Char' is the (`Index' + 1)-th character of `String'.
% Calls error/1 if `Index' is out of range (negative, or greater than
% or equal to the length of `String').
+ %
:- func string__index_det(string, int) = char.
:- pred string__index_det(string::in, int::in, char::uo) is det.
% A synonym for index_det/2:
% String ^ elem(Index) = string__index_det(String, Index).
+ %
:- func string ^ elem(int) = char.
% string__unsafe_index(String, Index, Char):
@@ -288,50 +322,60 @@
% This version is constant time, whereas string__index_det
% may be linear in the length of the string.
% Use with care!
+ %
:- func string__unsafe_index(string, int) = char.
:- pred string__unsafe_index(string::in, int::in, char::uo) is det.
% A synonym for unsafe_index/2:
% String ^ unsafe_elem(Index) = string__unsafe_index(String, Index).
+ %
:- func string ^ unsafe_elem(int) = char.
% string__chomp(String):
% `String' minus any single trailing newline character.
+ %
:- func string__chomp(string) = string.
% string__lstrip(String):
% `String' minus any initial whitespace characters.
+ %
:- func string__lstrip(string) = string.
% string__rstrip(String):
% `String' minus any trailing whitespace characters.
+ %
:- func string__rstrip(string) = string.
% string__strip(String):
% `String' minus any initial and trailing whitespace characters.
+ %
:- func string__strip(string) = string.
% string__lstrip(Pred, String):
% `String' minus the maximal prefix consisting entirely of
% chars satisfying `Pred'.
+ %
:- func string__lstrip(pred(char)::in(pred(in) is semidet), string::in)
= (string::out) is det.
% string__rstrip(Pred, String):
% `String' minus the maximal suffix consisting entirely of
% chars satisfying `Pred'.
+ %
:- func string__rstrip(pred(char)::in(pred(in) is semidet), string::in)
= (string::out) is det.
% string__prefix_length(Pred, String):
% The length of the maximal prefix of `String' consisting entirely of
% chars satisfying Pred.
+ %
:- func string__prefix_length(pred(char)::in(pred(in) is semidet), string::in)
= (int::out) is det.
% string__suffix_length(Pred, String):
% The length of the maximal suffix of `String' consisting entirely of
% chars satisfying Pred.
+ %
:- func suffix_length(pred(char)::in(pred(in) is semidet), string::in)
= (int::out) is det.
@@ -340,6 +384,7 @@
% set to `Char'.
% Fails if `Index' is out of range (negative, or greater than or
% equal to the length of `String0').
+ %
:- pred string__set_char(char, int, string, string).
:- mode string__set_char(in, in, in, out) is semidet.
% XXX This mode is disabled because the compiler puts constant
@@ -351,6 +396,7 @@
% set to `Char'.
% Calls error/1 if `Index' is out of range (negative, or greater than
% or equal to the length of `String0').
+ %
:- func string__set_char_det(char, int, string) = string.
:- pred string__set_char_det(char, int, string, string).
:- mode string__set_char_det(in, in, in, out) is det.
@@ -366,6 +412,7 @@
% This version is constant time, whereas string__set_char_det
% may be linear in the length of the string.
% Use with care!
+ %
:- func string__unsafe_set_char(char, int, string) = string.
:- mode string__unsafe_set_char(in, in, in) = out is det.
% XXX This mode is disabled because the compiler puts constant
@@ -385,6 +432,7 @@
% string__to_char_list(String, Chars),
% list__foldl(Closure, Chars, Acc0, Acc)
% but is implemented more efficiently.)
+ %
:- func string__foldl(func(char, T) = T, string, T) = T.
:- pred string__foldl(pred(char, T, T), string, T, T).
:- mode string__foldl(pred(in, in, out) is det, in, in, out) is det.
@@ -396,6 +444,7 @@
% string__foldl_substring(Closure, String, Start, Count, !Acc)
% is equivalent to string__foldl(Closure, SubString, !Acc)
% where SubString = string__substring(String, Start, Count).
+ %
:- func string__foldl_substring(func(char, T) = T, string, int, int, T) = T.
:- pred string__foldl_substring(pred(char, T, T), string, int, int, T, T).
:- mode string__foldl_substring(pred(in, in, out) is det, in, in, in,
@@ -411,6 +460,7 @@
% string__foldr(Closure, String, !Acc):
% As string__foldl/4, except that processing proceeds right-to-left.
+ %
:- func string__foldr(func(char, T) = T, string, T) = T.
:- pred string__foldr(pred(char, T, T), string, T, T).
:- mode string__foldr(pred(in, in, out) is det, in, in, out) is det.
@@ -422,6 +472,7 @@
% string__foldr_substring(Closure, String, Start, Count, !Acc)
% is equivalent to string__foldr(Closure, SubString, !Acc)
% where SubString = string__substring(String, Start, Count).
+ %
:- func string__foldr_substring(func(char, T) = T, string, int, int, T) = T.
:- pred string__foldr_substring(pred(char, T, T), string, int, int, T, T).
:- mode string__foldr_substring(pred(in, in, out) is det, in, in, in,
@@ -441,6 +492,7 @@
%
% string__words(char__is_whitespace, " the cat sat on the mat") =
% ["the", "cat", "sat", "on", "the", "mat"]
+ %
:- func string__words(pred(char), string) = list(string).
:- mode string__words(pred(in) is semidet, in) = out is det.
@@ -452,26 +504,24 @@
% and `RightSubstring' is the remainder of `String'.
% (If `Count' is out of the range [0, length of `String'], it is
% treated as if it were the nearest end-point of that range.)
-:- pred string__split(string, int, string, string).
-:- mode string__split(in, in, uo, uo) is det.
+ %
+:- pred string__split(string::in, int::in, string::uo, string::uo) is det.
% string__left(String, Count, LeftSubstring):
% `LeftSubstring' is the left-most `Count' characters of `String'.
% (If `Count' is out of the range [0, length of `String'], it is
% treated as if it were the nearest end-point of that range.)
-:- func string__left(string, int) = string.
-:- mode string__left(in, in) = uo is det.
-:- pred string__left(string, int, string).
-:- mode string__left(in, in, uo) is det.
+ %
+:- func string__left(string::in, int::in) = (string::uo) is det.
+:- pred string__left(string::in, int::in, string::uo) is det.
% string__right(String, Count, RightSubstring):
% `RightSubstring' is the right-most `Count' characters of `String'.
% (If `Count' is out of the range [0, length of `String'], it is
% treated as if it were the nearest end-point of that range.)
-:- func string__right(string, int) = string.
-:- mode string__right(in, in) = uo is det.
-:- pred string__right(string, int, string).
-:- mode string__right(in, in, uo) is det.
+ %
+:- func string__right(string::in, int::in) = (string::uo) is det.
+:- pred string__right(string::in, int::in, string::uo) is det.
% string__substring(String, Start, Count, Substring):
% `Substring' is first the `Count' characters in what would
@@ -481,6 +531,7 @@
% treated as if it were the nearest end-point of that range.
% If `Count' is out of the range [0, length of `String' - `Start'],
% it is treated as if it were the nearest end-point of that range.)
+ %
:- func string__substring(string, int, int) = string.
:- mode string__substring(in, in, in) = uo is det.
:- pred string__substring(string, int, int, string).
@@ -497,40 +548,43 @@
% This version takes time proportional to the length of the
% substring, whereas string__substring may take time proportional
% to the length of the whole string.
+ %
:- func string__unsafe_substring(string, int, int) = string.
:- mode string__unsafe_substring(in, in, in) = uo is det.
:- pred string__unsafe_substring(string, int, int, string).
:- mode string__unsafe_substring(in, in, in, uo) is det.
% Append a list of strings together.
+ %
:- func string__append_list(list(string)::in) = (string::uo) is det.
-:- pred string__append_list(list(string), string).
-:- mode string__append_list(in, uo) is det.
+:- pred string__append_list(list(string)::in, string::uo) is det.
% string__join_list(Separator, Strings) = JoinedString:
% Appends together the strings in Strings, putting Separator between
% adjacent strings. If Strings is the empty list, returns the empty
% string.
+ %
:- func string__join_list(string::in, list(string)::in) = (string::uo) is det.
% Compute a hash value for a string.
+ %
:- func string__hash(string) = int.
-:- pred string__hash(string, int).
-:- mode string__hash(in, out) is det.
+:- pred string__hash(string::in, int::out) is det.
% string__sub_string_search(String, SubString, Index).
% `Index' is the position in `String' where the first occurrence of
% `SubString' begins. Indices start at zero, so if `SubString'
% is a prefix of `String', this will return Index = 0.
-:- pred string__sub_string_search(string, string, int).
-:- mode string__sub_string_search(in, in, out) is semidet.
+ %
+:- pred string__sub_string_search(string::in, string::in, int::out) is semidet.
% string__sub_string_search(String, SubString, BeginAt, Index).
% `Index' is the position in `String' where the first occurrence of
% `SubString' occurs such that 'Index' is greater than or equal to
% `BeginAt'. Indices start at zero,
-:- pred string__sub_string_search(string, string, int, int).
-:- mode string__sub_string_search(in, in, in, out) is semidet.
+ %
+:- pred string__sub_string_search(string::in, string::in, int::in, int::out)
+ is semidet.
% A function similar to sprintf() in C.
%
@@ -584,8 +638,8 @@
% actual output will depend on the C standard library.
%
:- func string__format(string, list(string__poly_type)) = string.
-:- pred string__format(string, list(string__poly_type), string).
-:- mode string__format(in, in, out) is det.
+:- pred string__format(string::in, list(string__poly_type)::in, string::out)
+ is det.
%------------------------------------------------------------------------------%
@@ -596,6 +650,7 @@
; c(char).
%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
:- implementation.
:- import_module array, bool, float, int, integer, require, std_util.
Index: library/term.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/term.m,v
retrieving revision 1.109
diff -u -r1.109 term.m
--- library/term.m 15 Dec 2004 06:57:41 -0000 1.109
+++ library/term.m 18 Jan 2005 12:10:52 -0000
@@ -75,6 +75,7 @@
% offending part of the term was read in from, if available.
% ArgContexts specifies the path from the root of the term
% to the offending subterm.
+ %
:- func term__try_term_to_type(term(U)) = term_to_type_result(T, U).
:- pred term__try_term_to_type(term(U)::in, term_to_type_result(T, U)::out)
is det.
@@ -101,18 +102,22 @@
).
% term_to_type(Term, Type) :- try_term_to_type(Term, ok(Type)).
+ %
:- pred term__term_to_type(term(U)::in, T::out) is semidet.
- % like term_to_type, but calls error/1 rather than failing.
+ % Like term_to_type, but calls error/1 rather than failing.
+ %
:- func term__det_term_to_type(term(_)) = T.
:- pred term__det_term_to_type(term(_)::in, T::out) is det.
- % converts a value to a term representation of that value
+ % Converts a value to a term representation of that value.
+ %
:- func term__type_to_term(T) = term(_).
:- pred term__type_to_term(T::in, term(_)::out) is det.
% calls term__type_to_term on the value stored in the univ
% (as distinct from the univ itself).
+ %
:- func term__univ_to_term(univ) = term(_).
:- pred term__univ_to_term(univ::in, term(_)::out) is det.
@@ -121,22 +126,26 @@
% term__vars(Term, Vars)
% Vars is the list of variables contained in Term, in the order
% obtained by traversing the term depth first, left-to-right.
+ %
:- func term__vars(term(T)) = list(var(T)).
:- pred term__vars(term(T)::in, list(var(T))::out) is det.
% As above, but with an accumulator.
+ %
:- func term__vars_2(term(T), list(var(T))) = list(var(T)).
:- pred term__vars_2(term(T)::in, list(var(T))::in, list(var(T))::out) is det.
% term__vars_list(TermList, Vars)
% Vars is the list of variables contained in TermList, in the order
% obtained by traversing the list of terms depth-first, left-to-right.
+ %
:- func term__vars_list(list(term(T))) = list(var(T)).
:- pred term__vars_list(list(term(T))::in, list(var(T))::out) is det.
% term__contains_var(Term, Var)
% True if Term contains Var. On backtracking returns all the
% variables contained in Term.
+ %
:- pred term__contains_var(term(T), var(T)).
:- mode term__contains_var(in, in) is semidet.
:- mode term__contains_var(in, out) is nondet.
@@ -144,6 +153,7 @@
% term__contains_var_list(TermList, Var)
% True if TermList contains Var. On backtracking returns all the
% variables contained in Term.
+ %
:- pred term__contains_var_list(list(term(T)), var(T)).
:- mode term__contains_var_list(in, in) is semidet.
:- mode term__contains_var_list(in, out) is nondet.
@@ -154,17 +164,20 @@
% term__unify(Term1, Term2, Bindings0, Bindings):
% Unify (with occur check) two terms with respect to a set of bindings
% and possibly update the set of bindings.
+ %
:- pred term__unify(term(T)::in, term(T)::in, substitution(T)::in,
substitution(T)::out) is semidet.
% term__substitute(Term0, Var, Replacement, Term):
% Replace all occurrences of Var in Term0 with Replacement,
% and return the result in Term.
+ %
:- func term__substitute(term(T), var(T), term(T)) = term(T).
:- pred term__substitute(term(T)::in, var(T)::in, term(T)::in, term(T)::out)
is det.
% As above, except for a list of terms rather than a single term.
+ %
:- func term__substitute_list(list(term(T)), var(T), term(T)) = list(term(T)).
:- pred term__substitute_list(list(term(T))::in, var(T)::in, term(T)::in,
list(term(T))::out) is det.
@@ -174,6 +187,7 @@
% term in Repls, and return the result in Term. If Vars contains
% duplicates, or if Vars is not the same length as Repls, the
% behaviour is undefined and probably harmful.
+ %
:- func term__substitute_corresponding(list(var(T)), list(term(T)),
term(T)) = term(T).
:- pred term__substitute_corresponding(list(var(T))::in, list(term(T))::in,
@@ -181,6 +195,7 @@
% As above, except applies to a list of terms rather than a
% single term.
+ %
:- func term__substitute_corresponding_list(list(var(T)),
list(term(T)), list(term(T))) = list(term(T)).
:- pred term__substitute_corresponding_list(list(var(T))::in,
@@ -189,12 +204,14 @@
% term__apply_rec_substitution(Term0, Substitution, Term):
% Recursively apply substitution to Term0 until no more substitions
% can be applied, and then return the result in Term.
+ %
:- func term__apply_rec_substitution(term(T), substitution(T)) = term(T).
:- pred term__apply_rec_substitution(term(T)::in, substitution(T)::in,
term(T)::out) is det.
% As above, except applies to a list of terms rather than a
% single term.
+ %
:- func term__apply_rec_substitution_to_list(list(term(T)),
substitution(T)) = list(term(T)).
:- pred term__apply_rec_substitution_to_list(list(term(T))::in,
@@ -202,12 +219,14 @@
% term__apply_substitution(Term0, Substitution, Term):
% Apply substitution to Term0 and return the result in Term.
+ %
:- func term__apply_substitution(term(T), substitution(T)) = term(T).
:- pred term__apply_substitution(term(T)::in, substitution(T)::in,
term(T)::out) is det.
% As above, except applies to a list of terms rather than a
% single term.
+ %
:- func term__apply_substitution_to_list(list(term(T)),
substitution(T)) = list(term(T)).
:- pred term__apply_substitution_to_list(list(term(T))::in,
@@ -216,15 +235,18 @@
% term__occurs(Term0, Var, Substitution):
% True iff Var occurs in the term resulting after applying
% Substitution to Term0.
+ %
:- pred term__occurs(term(T)::in, var(T)::in, substitution(T)::in) is semidet.
% As above, except for a list of terms rather than a single term.
+ %
:- pred term__occurs_list(list(term(T))::in, var(T)::in, substitution(T)::in)
is semidet.
% term__relabel_variable(Term0, OldVar, NewVar, Term):
% Replace all occurences of OldVar in Term0 with NewVar and
% put the result in Term.
+ %
:- func term__relabel_variable(term(T), var(T), var(T)) = term(T).
:- pred term__relabel_variable(term(T)::in, var(T)::in, var(T)::in,
term(T)::out) is det.
@@ -232,29 +254,34 @@
% As above, except applies to a list of terms rather than a
% single term.
% XXX the name of the predicate is misleading.
+ %
:- func term__relabel_variables(list(term(T)), var(T), var(T)) = list(term(T)).
:- pred term__relabel_variables(list(term(T))::in, var(T)::in, var(T)::in,
list(term(T))::out) is det.
% Same as term__relabel_variable, except relabels multiple variables.
% If a variable is not in the map, it is not replaced.
+ %
:- func term__apply_variable_renaming(term(T), map(var(T), var(T))) = term(T).
:- pred term__apply_variable_renaming(term(T)::in, map(var(T), var(T))::in,
term(T)::out) is det.
% Applies term__apply_variable_renaming to a list of terms.
+ %
:- func term__apply_variable_renaming_to_list(list(term(T)),
map(var(T), var(T))) = list(term(T)).
:- pred term__apply_variable_renaming_to_list(list(term(T))::in,
map(var(T), var(T))::in, list(term(T))::out) is det.
% Applies term__apply_variable_renaming to a var.
+ %
:- func term__apply_variable_renaming_to_var(map(var(T), var(T)),
var(T)) = var(T).
:- pred term__apply_variable_renaming_to_var(map(var(T), var(T))::in,
var(T)::in, var(T)::out) is det.
% Applies term__apply_variable_renaming to a list of vars.
+ %
:- func term__apply_variable_renaming_to_vars(map(var(T), var(T)),
list(var(T))) = list(var(T)).
:- pred term__apply_variable_renaming_to_vars(map(var(T), var(T))::in,
@@ -262,9 +289,11 @@
% term__is_ground(Term, Bindings) is true iff no variables contained
% in Term are non-ground in Bindings.
+ %
:- pred term__is_ground(term(T)::in, substitution(T)::in) is semidet.
% term__is_ground(Term) is true iff Term contains no variables.
+ %
:- pred term__is_ground(term(T)::in) is semidet.
%-----------------------------------------------------------------------------%
@@ -274,6 +303,7 @@
% term__init_var_supply(VarSupply):
% Returns a fresh var_supply for producing fresh variables.
+ %
:- func term__init_var_supply = var_supply(T).
:- pred term__init_var_supply(var_supply(T)).
:- mode term__init_var_supply(out) is det.
@@ -281,12 +311,14 @@
% term__create_var(VarSupply0, Variable, VarSupply):
% Create a fresh variable (var) and return the updated var_supply.
+ %
:- pred term__create_var(var_supply(T), var(T), var_supply(T)).
:- mode term__create_var(in, out, out) is det.
% term__var_id(Variable):
% Returns a unique number associated with this variable w.r.t.
% its originating var_supply.
+ %
:- func term__var_id(var(T)) = int.
%-----------------------------------------------------------------------------%
@@ -300,43 +332,46 @@
% Convert a variable to an int.
% Different variables map to different ints.
% Other than that, the mapping is unspecified.
+ %
:- func term__var_to_int(var(T)) = int.
:- pred term__var_to_int(var(T)::in, int::out) is det.
%-----------------------------------------------------------------------------%
% Given a term context, return the source line number.
-:- pred term__context_line(term__context::in, int::out) is det.
+ %
:- func term__context_line(term__context) = int.
+:- pred term__context_line(term__context::in, int::out) is det.
% Given a term context, return the source file.
-:- pred term__context_file(term__context::in, string::out) is det.
+ %
:- func term__context_file(term__context) = string.
+:- pred term__context_file(term__context::in, string::out) is det.
% Used to initialize the term context when reading in
% (or otherwise constructing) a term.
-:- pred term__context_init(term__context::out) is det.
+ %
:- func term__context_init = term__context.
-:- pred term__context_init(string::in, int::in, term__context::out) is det.
+:- pred term__context_init(term__context::out) is det.
:- func term__context_init(string, int) = term__context.
+:- pred term__context_init(string::in, int::in, term__context::out) is det.
% Convert a list of terms which are all vars into a list
% of vars. Abort (call error/1) if the list contains
% any non-variables.
-
+ %
+:- func term__term_list_to_var_list(list(term(T))) = list(var(T)).
:- pred term__term_list_to_var_list(list(term(T))::in, list(var(T))::out)
is det.
-:- func term__term_list_to_var_list(list(term(T))) = list(var(T)).
% Convert a list of terms which are all vars into a list
% of vars (or vice versa).
-
+ %
+:- func term__var_list_to_term_list(list(var(T))) = list(term(T)).
:- pred term__var_list_to_term_list(list(var(T)), list(term(T))).
:- mode term__var_list_to_term_list(in, out) is det.
:- mode term__var_list_to_term_list(out, in) is semidet.
-:- func term__var_list_to_term_list(list(var(T))) = list(term(T)).
-
%-----------------------------------------------------------------------------%
% term__generic_term(Term) is true iff `Term' is a term of type
@@ -344,21 +379,26 @@
% It is useful because in some instances it doesn't matter what
% the type of a term is, and passing it to this predicate will
% ground the type avoiding unbound type variable warnings.
+ %
:- pred term__generic_term(term::in) is det.
% Coerce a term of type `T' into a term of type `U'.
-:- pred term__coerce(term(T)::in, term(U)::out) is det.
+ %
:- func term__coerce(term(T)) = term(U).
+:- pred term__coerce(term(T)::in, term(U)::out) is det.
% Coerce a var of type `T' into a var of type `U'.
-:- pred term__coerce_var(var(T)::in, var(U)::out) is det.
+ %
:- func term__coerce_var(var(T)) = var(U).
+:- pred term__coerce_var(var(T)::in, var(U)::out) is det.
% Coerce a var_supply of type `T' into a var_supply of type `U'.
-:- pred term__coerce_var_supply(var_supply(T)::in, var_supply(U)::out) is det.
+ %
:- func term__coerce_var_supply(var_supply(T)) = var_supply(U).
+:- pred term__coerce_var_supply(var_supply(T)::in, var_supply(U)::out) is det.
%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
:- implementation.
Index: library/term_io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/term_io.m,v
retrieving revision 1.71
diff -u -r1.71 term_io.m
--- library/term_io.m 19 Jan 2005 03:11:19 -0000 1.71
+++ library/term_io.m 19 Jan 2005 04:21:53 -0000
@@ -44,80 +44,101 @@
% except that resulting term is in the ground representation.
% Binds Result to either `eof', `term(VarSet, Term)', or
% `error(Message, LineNumber)'.
+ %
:- pred term_io__read_term(read_term(T)::out, io::di, io::uo) is det.
% As above, except uses the given operator table instead of
% the standard Mercury operators.
+ %
:- pred term_io__read_term_with_op_table(Ops::in, read_term(T)::out,
io::di, io::uo) is det <= op_table(Ops).
% Writes a term to standard output.
+ %
:- pred term_io__write_term(varset(T)::in, term(T)::in, io::di, io::uo) is det.
% As above, except uses the given operator table instead of the
% standard Mercury operators.
+ %
:- pred term_io__write_term_with_op_table(Ops::in, varset(T)::in, term(T)::in,
io::di, io::uo) is det <= op_table(Ops).
% As above, except it appends a period and new-line.
+ %
:- pred term_io__write_term_nl(varset(T)::in, term(T)::in, io::di, io::uo)
is det.
% As above, except it appends a period and new-line.
+ %
:- pred term_io__write_term_nl_with_op_table(Ops::in, varset(T)::in,
term(T)::in, io::di, io::uo) is det <= op_table(Ops).
% Writes a constant (integer, float, string, or atom) to stdout.
+ %
:- pred term_io__write_constant(const::in, io::di, io::uo) is det.
% Like term_io__write_constant, but return the result in a string.
+ %
:- func term_io__format_constant(const) = string.
% Writes a variable to stdout.
+ %
:- pred term_io__write_variable(var(T)::in, varset(T)::in, io::di, io::uo)
is det.
% As above, except uses the given operator table instead of the
% standard Mercury operators.
+ %
:- pred term_io__write_variable_with_op_table(Ops::in, var(T)::in,
varset(T)::in, io::di, io::uo) is det <= op_table(Ops).
% Given a string S, write S in double-quotes, with characters
% escaped if necessary, to stdout.
+ %
:- pred term_io__quote_string(string::in, io::di, io::uo) is det.
% Like term_io__quote_string, but return the result in a string.
+ %
:- func term_io__quoted_string(string) = string.
% Given an atom-name A, write A, enclosed in single-quotes if necessary,
% with characters escaped if necessary, to stdout.
+ %
:- pred term_io__quote_atom(string::in, io::di, io::uo) is det.
% Like term_io__quote_atom, but return the result in a string.
+ %
:- func term_io__quoted_atom(string) = string.
% Given a character C, write C in single-quotes,
% escaped if necessary, to stdout.
+ %
:- pred term_io__quote_char(char::in, io::di, io::uo) is det.
-:- func term_io__quoted_char(char) = string.
% Like term_io__quote_char, but return the result in a string.
+ %
+:- func term_io__quoted_char(char) = string.
% Given a character C, write C, escaped if necessary, to stdout.
% The character is not enclosed in quotes.
+ %
:- pred term_io__write_escaped_char(char::in, io::di, io::uo) is det.
% Like term_io__write_escaped_char, but return the result in a string.
+ %
:- func term_io__escaped_char(char) = string.
% Given a string S, write S, with characters escaped if necessary,
% to stdout. The string is not enclosed in quotes.
+ %
:- pred term_io__write_escaped_string(string::in, io::di, io::uo) is det.
% Like term_io__write_escaped_char, but return the result in a string.
+ %
:- func term_io__escaped_string(string) = string.
%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
:- implementation.
Index: library/term_to_xml.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/term_to_xml.m,v
retrieving revision 1.4
diff -u -r1.4 term_to_xml.m
--- library/term_to_xml.m 15 Dec 2004 04:40:23 -0000 1.4
+++ library/term_to_xml.m 18 Jan 2005 11:46:00 -0000
@@ -224,8 +224,8 @@
% will be be written out in full. If an embedded DTD is requested, but
% it is not possible to generate a DTD for Term using ElementMapping,
% then a value other than `ok' is returned in DTDResult and nothing is
- % written out. See the dtd_generation_result type for a list of the other
- % possible values of DTDResult and their meanings.
+ % written out. See the dtd_generation_result type for a list of the
+ % other possible values of DTDResult and their meanings.
%
:- pred write_xml_doc_cc(T::in, element_mapping::in(element_mapping),
maybe_stylesheet::in, maybe_dtd::in, dtd_generation_result::out,
Index: library/tree234.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/tree234.m,v
retrieving revision 1.45
diff -u -r1.45 tree234.m
--- library/tree234.m 13 Jan 2005 11:04:37 -0000 1.45
+++ library/tree234.m 19 Jan 2005 03:20:34 -0000
@@ -21,99 +21,77 @@
:- type tree234(K, V).
-:- pred tree234__init(tree234(K, V)).
-:- mode tree234__init(uo) is det.
-
:- func tree234__init = tree234(K, V).
+:- pred tree234__init(tree234(K, V)::uo) is det.
-:- pred tree234__is_empty(tree234(K, V)).
-:- mode tree234__is_empty(in) is semidet.
-
-:- pred tree234__member(tree234(K, V), K, V).
-:- mode tree234__member(in, out, out) is nondet.
+:- pred tree234__is_empty(tree234(K, V)::in) is semidet.
-:- pred tree234__search(tree234(K, V), K, V).
-:- mode tree234__search(in, in, out) is semidet.
+:- pred tree234__member(tree234(K, V)::in, K::out, V::out) is nondet.
-:- pred tree234__lookup(tree234(K, V), K, V).
-:- mode tree234__lookup(in, in, out) is det.
+:- pred tree234__search(tree234(K, V)::in, K::in, V::out) is semidet.
:- func tree234__lookup(tree234(K, V), K) = V.
+:- pred tree234__lookup(tree234(K, V)::in, K::in, V::out) is det.
% Search for a key-value pair using the key. If there is no entry
% for the given key, returns the pair for the next lower key instead.
% Fails if there is no key with the given or lower value.
-:- pred tree234__lower_bound_search(tree234(K, V), K, K, V).
-:- mode tree234__lower_bound_search(in, in, out, out) is semidet.
+ %
+:- pred tree234__lower_bound_search(tree234(K, V)::in, K::in, K::out, V::out)
+ is semidet.
% Search for a key-value pair using the key. If there is no entry
% for the given key, returns the pair for the next lower key instead.
% Aborts if there is no key with the given or lower value.
-:- pred tree234__lower_bound_lookup(tree234(K, V), K, K, V).
-:- mode tree234__lower_bound_lookup(in, in, out, out) is det.
+ %
+:- pred tree234__lower_bound_lookup(tree234(K, V)::in, K::in, K::out, V::out)
+ is det.
% Search for a key-value pair using the key. If there is no entry
% for the given key, returns the pair for the next higher key instead.
% Fails if there is no key with the given or higher value.
-:- pred tree234__upper_bound_search(tree234(K, V), K, K, V).
-:- mode tree234__upper_bound_search(in, in, out, out) is semidet.
+ %
+:- pred tree234__upper_bound_search(tree234(K, V)::in, K::in, K::out, V::out)
+ is semidet.
% Search for a key-value pair using the key. If there is no entry
% for the given key, returns the pair for the next higher key instead.
% Aborts if there is no key with the given or higher value.
-:- pred tree234__upper_bound_lookup(tree234(K, V), K, K, V).
-:- mode tree234__upper_bound_lookup(in, in, out, out) is det.
+ %
+:- pred tree234__upper_bound_lookup(tree234(K, V)::in, K::in, K::out, V::out)
+ is det.
:- func tree234__max_key(tree234(K, V)) = K is semidet.
:- func tree234__min_key(tree234(K, V)) = K is semidet.
-:- pred tree234__insert(tree234(K, V), K, V, tree234(K, V)).
-:- mode tree234__insert(in, in, in, out) is semidet.
-% :- mode tree234__insert(di_tree234, in, in, uo_tree234) is semidet.
-% :- mode tree234__insert(in, in, in, out) is semidet.
-
-:- pred tree234__set(tree234(K, V), K, V, tree234(K, V)).
-:- mode tree234__set(di, di, di, uo) is det.
-% :- mode tree234__set(di_tree234, in, in, uo_tree234) is det.
-:- mode tree234__set(in, in, in, out) is det.
+:- pred tree234__insert(tree234(K, V)::in, K::in, V::in, tree234(K, V)::out)
+ is semidet.
:- func tree234__set(tree234(K, V), K, V) = tree234(K, V).
-
-:- pred tree234__delete(tree234(K, V), K, tree234(K, V)).
-:- mode tree234__delete(di, in, uo) is det.
-% :- mode tree234__delete(di_tree234, in, uo_tree234) is det.
-:- mode tree234__delete(in, in, out) is det.
+:- pred tree234__set(tree234(K, V)::in, K::in, V::in, tree234(K, V)::out)
+ is det.
:- func tree234__delete(tree234(K, V), K) = tree234(K, V).
+:- pred tree234__delete(tree234(K, V)::in, K::in, tree234(K, V)::out) is det.
:- pred tree234__remove(tree234(K, V), K, V, tree234(K, V)).
-:- mode tree234__remove(di, in, uo, uo) is semidet.
-% :- mode tree234__remove(di_tree234, in, out, uo_tree234) is semidet.
:- mode tree234__remove(in, in, out, out) is semidet.
:- pred tree234__remove_smallest(tree234(K, V), K, V, tree234(K, V)).
-:- mode tree234__remove_smallest(di, uo, uo, uo) is semidet.
-% :- mode tree234__remove_smallest(di_tree234, out, out, uo_tree234)
-% is semidet.
:- mode tree234__remove_smallest(in, out, out, out) is semidet.
% Given a tree234, return a list of all the keys in the tree.
% The list that is returned is in sorted order.
-:- pred tree234__keys(tree234(K, V), list(K)).
-:- mode tree234__keys(in, out) is det.
-
+ %
:- func tree234__keys(tree234(K, V)) = list(K).
-
-:- pred tree234__values(tree234(K, V), list(V)).
-:- mode tree234__values(in, out) is det.
+:- pred tree234__keys(tree234(K, V)::in, list(K)::out) is det.
:- func tree234__values(tree234(K, V)) = list(V).
+:- pred tree234__values(tree234(K, V)::in, list(V)::out) is det.
-:- pred tree234__update(tree234(K, V), K, V, tree234(K, V)).
-:- mode tree234__update(in, in, in, out) is semidet.
-% :- mode tree234__update(di_tree234, in, in, uo_tree234) is det.
-% :- mode tree234__update(di, di, di, uo) is semidet.
+:- pred tree234__update(tree234(K, V)::in, K::in, V::in, tree234(K, V)::out)
+ is semidet.
% Update the value at the given key by applying the supplied
% transformation to it. This is faster than first searching for
@@ -122,24 +100,24 @@
:- pred tree234__transform_value(pred(V, V)::in(pred(in, out) is det), K::in,
tree234(K, V)::in, tree234(K, V)::out) is semidet.
- % count the number of elements in a tree
-:- pred tree234__count(tree234(K, V), int).
-:- mode tree234__count(in, out) is det.
-
+ % Count the number of elements in a tree.
+ %
:- func tree234__count(tree234(K, V)) = int.
-
-:- pred tree234__assoc_list_to_tree234(assoc_list(K, V), tree234(K, V)).
-:- mode tree234__assoc_list_to_tree234(in, out) is det.
+:- pred tree234__count(tree234(K, V)::in, int::out) is det.
:- func tree234__assoc_list_to_tree234(assoc_list(K, V)) = tree234(K, V).
+:- pred tree234__assoc_list_to_tree234(assoc_list(K, V)::in,
+ tree234(K, V)::out) is det.
% Given a tree234, return an association list of all the
% keys and values in the tree. The association list that
% is returned is sorted on the keys.
-:- pred tree234__tree234_to_assoc_list(tree234(K, V), assoc_list(K, V)).
-:- mode tree234__tree234_to_assoc_list(in, out) is det.
-
+ %
:- func tree234__tree234_to_assoc_list(tree234(K, V)) = assoc_list(K, V).
+:- pred tree234__tree234_to_assoc_list(tree234(K, V)::in,
+ assoc_list(K, V)::out) is det.
+
+:- func tree234__foldl(func(K, V, T) = T, tree234(K, V), T) = T.
:- pred tree234__foldl(pred(K, V, T, T), tree234(K, V), T, T).
:- mode tree234__foldl(pred(in, in, in, out) is det, in, in, out) is det.
@@ -147,8 +125,6 @@
is semidet.
:- mode tree234__foldl(pred(in, in, di, uo) is det, in, di, uo) is det.
-:- func tree234__foldl(func(K, V, T) = T, tree234(K, V), T) = T.
-
:- pred tree234__foldl2(pred(K, V, T, T, U, U), tree234(K, V), T, T, U, U).
:- mode tree234__foldl2(pred(in, in, in, out, in, out) is det,
in, in, out, in, out) is det.
@@ -172,12 +148,12 @@
:- mode tree234__foldl3(pred(in, in, di, uo, di, uo, di, uo) is det,
in, di, uo, di, uo, di, uo) is det.
+:- func tree234__map_values(func(K, V) = W, tree234(K, V)) = tree234(K, W).
+
:- pred tree234__map_values(pred(K, V, W), tree234(K, V), tree234(K, W)).
:- mode tree234__map_values(pred(in, in, out) is det, in, out) is det.
:- mode tree234__map_values(pred(in, in, out) is semidet, in, out) is semidet.
-:- func tree234__map_values(func(K, V) = W, tree234(K, V)) = tree234(K, W).
-
:- pred tree234__map_foldl(pred(K, V, W, A, A), tree234(K, V), tree234(K, W),
A, A).
:- mode tree234__map_foldl(pred(in, in, out, di, uo) is det,
Index: library/type_desc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/type_desc.m,v
retrieving revision 1.30
diff -u -r1.30 type_desc.m
--- library/type_desc.m 16 Dec 2004 07:05:09 -0000 1.30
+++ library/type_desc.m 18 Jan 2005 11:31:16 -0000
@@ -47,6 +47,7 @@
% This function allows the caller to look into the structure
% of the given pseudo_type_desc.
+ %
:- func pseudo_type_desc_to_rep(pseudo_type_desc) = pseudo_type_rep.
% Convert a type_desc, which by definition describes a ground
@@ -56,11 +57,13 @@
% Convert a pseudo_type_desc describing a ground type to a type_desc.
% If the pseudo_type_desc describes a non-ground type, fail.
+ %
:- func ground_pseudo_type_desc_to_type_desc(pseudo_type_desc) = type_desc
is semidet.
% Convert a pseudo_type_desc describing a ground type to a type_desc.
% If the pseudo_type_desc describes a non-ground type, abort.
+ %
:- func ground_pseudo_type_desc_to_type_desc_det(pseudo_type_desc) = type_desc
is det.
@@ -82,6 +85,7 @@
% inverse to the function type_of/1. It constrains the type
% of the first argument to be the type represented by the
% second argument.
+ %
:- some [T] pred has_type(T::unused, type_desc__type_desc::in) is det.
% type_name(Type) returns the name of the specified type
@@ -205,6 +209,7 @@
type_desc__type_desc.
%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
:- implementation.
Index: library/varset.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/varset.m,v
retrieving revision 1.71
diff -u -r1.71 varset.m
--- library/varset.m 15 Dec 2004 06:57:41 -0000 1.71
+++ library/varset.m 18 Jan 2005 11:18:15 -0000
@@ -34,93 +34,101 @@
:- type varset == varset(generic).
- % construct an empty varset.
-:- pred varset__init(varset(T)::out) is det.
-
+ % Construct an empty varset.
+ %
:- func varset__init = varset(T).
+:- pred varset__init(varset(T)::out) is det.
- % check whether a varset is empty.
+ % Check whether a varset is empty.
+ %
:- pred varset__is_empty(varset(T)::in) is semidet.
- % create a new variable
+ % Create a new variable.
+ %
:- pred varset__new_var(varset(T)::in, var(T)::out, varset(T)::out) is det.
- % create a new named variable
+ % Create a new named variable.
+ %
:- pred varset__new_named_var(varset(T)::in, string::in, var(T)::out,
varset(T)::out) is det.
- % create a new named variable with a unique (w.r.t. the
+ % Create a new named variable with a unique (w.r.t. the
% varset) number appended to the name.
+ %
:- pred varset__new_uniquely_named_var(varset(T)::in, string::in, var(T)::out,
varset(T)::out) is det.
- % create a new variable, and maybe give it a name
+ % Create a new variable, and maybe give it a name.
+ %
:- pred varset__new_maybe_named_var(varset(T)::in, maybe(string)::in,
var(T)::out, varset(T)::out) is det.
- % create multiple new variables
+ % Create multiple new variables.
+ %
:- pred varset__new_vars(varset(T)::in, int::in, list(var(T))::out,
varset(T)::out) is det.
- % delete the name and value for a variable
-:- pred varset__delete_var(varset(T)::in, var(T)::in, varset(T)::out) is det.
-
+ % Delete the name and value for a variable.
+ %
:- func varset__delete_var(varset(T), var(T)) = varset(T).
+:- pred varset__delete_var(varset(T)::in, var(T)::in, varset(T)::out) is det.
- % delete the names and values for a list of variables
+ % Delete the names and values for a list of variables.
+ %
+:- func varset__delete_vars(varset(T), list(var(T))) = varset(T).
:- pred varset__delete_vars(varset(T)::in, list(var(T))::in, varset(T)::out)
is det.
-:- func varset__delete_vars(varset(T), list(var(T))) = varset(T).
-
- % return a list of all the variables in a varset
-:- pred varset__vars(varset(T)::in, list(var(T))::out) is det.
-
+ % Return a list of all the variables in a varset.
+ %
:- func varset__vars(varset(T)) = list(var(T)).
+:- pred varset__vars(varset(T)::in, list(var(T))::out) is det.
- % set the name of a variable
+ % Set the name of a variable.
+ %
+:- func varset__name_var(varset(T), var(T), string) = varset(T).
:- pred varset__name_var(varset(T)::in, var(T)::in, string::in, varset(T)::out)
is det.
-:- func varset__name_var(varset(T), var(T), string) = varset(T).
-
- % lookup the name of a variable;
- % create one if it doesn't have one using V_ as a prefix
-:- pred varset__lookup_name(varset(T)::in, var(T)::in, string::out) is det.
-
+ % Lookup the name of a variable;
+ % create one if it doesn't have one using V_ as a prefix.
+ %
:- func varset__lookup_name(varset(T), var(T)) = string.
+:- pred varset__lookup_name(varset(T)::in, var(T)::in, string::out) is det.
- % lookup the name of a variable;
+ % Lookup the name of a variable;
% create one if it doesn't have one using the specified prefix
+ %
+:- func varset__lookup_name(varset(T), var(T), string) = string.
:- pred varset__lookup_name(varset(T)::in, var(T)::in, string::in, string::out)
is det.
-:- func varset__lookup_name(varset(T), var(T), string) = string.
-
- % lookup the name of a variable;
+ % Lookup the name of a variable;
% fail if it doesn't have one
+ %
:- pred varset__search_name(varset(T)::in, var(T)::in, string::out) is semidet.
- % bind a value to a variable
+ % Bind a value to a variable
% (will overwrite any existing binding).
+ %
+:- func varset__bind_var(varset(T), var(T), term(T)) = varset(T).
:- pred varset__bind_var(varset(T)::in, var(T)::in, term(T)::in,
varset(T)::out) is det.
-:- func varset__bind_var(varset(T), var(T), term(T)) = varset(T).
-
- % bind a set of terms to a set of variables.
+ % Bind a set of terms to a set of variables.
+ %
+:- func varset__bind_vars(varset(T), substitution(T)) = varset(T).
:- pred varset__bind_vars(varset(T)::in, substitution(T)::in, varset(T)::out)
is det.
-:- func varset__bind_vars(varset(T), substitution(T)) = varset(T).
-
- % lookup the value of a variable
+ % Lookup the value of a variable.
+ %
:- pred varset__search_var(varset(T)::in, var(T)::in, term(T)::out) is semidet.
- % get the bindings for all the bound variables.
-:- pred varset__lookup_vars(varset(T)::in, substitution(T)::out) is det.
-
+ % Get the bindings for all the bound variables.
+ %
:- func varset__lookup_vars(varset(T)) = substitution(T).
+:- pred varset__lookup_vars(varset(T)::in, substitution(T)::out) is det.
% Combine two different varsets, renaming apart:
% varset__merge(VarSet0, NewVarSet, VarSet, Subst) is
@@ -129,14 +137,14 @@
% (Any bindings in NewVarSet are ignored.)
% Subst is a substitution which maps the variables in NewVarSet
% into the corresponding fresh variable in VarSet.
-
+ %
:- pred varset__merge_subst(varset(T)::in, varset(T)::in, varset(T)::out,
substitution(T)::out) is det.
% varset__merge(VarSet0, NewVarSet, Terms0, VarSet, Terms):
% As varset__merge_subst, except instead of returning the substitution,
% this predicate applies it to the given list of terms.
-
+ %
:- pred varset__merge(varset(T)::in, varset(T)::in, list(term(T))::in,
varset(T)::out, list(term(T))::out) is det.
@@ -144,7 +152,7 @@
% in NewVarSet are not included in the final varset.
% This is useful if varset__create_name_var_map needs
% to be used on the resulting varset.
-
+ %
:- pred varset__merge_subst_without_names(varset(T)::in,
varset(T)::in, varset(T)::out, substitution(T)::out) is det.
@@ -152,68 +160,72 @@
% in NewVarSet are not included in the final varset.
% This is useful if varset__create_name_var_map needs
% to be used on the resulting varset.
-
+ %
:- pred varset__merge_without_names(varset(T)::in, varset(T)::in,
list(term(T))::in, varset(T)::out, list(term(T))::out) is det.
- % get the bindings for all the bound variables.
-:- pred varset__get_bindings(varset(T)::in, substitution(T)::out) is det.
-
+ % Get the bindings for all the bound variables.
+ %
:- func varset__get_bindings(varset(T)) = substitution(T).
+:- pred varset__get_bindings(varset(T)::in, substitution(T)::out) is det.
- % set the bindings for all the bound variables.
+ % Set the bindings for all the bound variables.
+ %
+:- func varset__set_bindings(varset(T), substitution(T)) = varset(T).
:- pred varset__set_bindings(varset(T)::in, substitution(T)::in,
varset(T)::out) is det.
-:- func varset__set_bindings(varset(T), substitution(T)) = varset(T).
-
% Create a map from names to variables.
% Each name is mapped to only one variable, even if a name is
% shared by more than one variable. Therefore this predicate
% is only really useful if it is already known that no two
% variables share the same name.
+ %
+:- func varset__create_name_var_map(varset(T)) = map(string, var(T)).
:- pred varset__create_name_var_map(varset(T)::in, map(string, var(T))::out)
is det.
-:- func varset__create_name_var_map(varset(T)) = map(string, var(T)).
-
% Return an association list giving the name of each variable.
% Every variable has an entry in the returned association list,
% even if it shares its name with another variable.
+ %
+:- func varset__var_name_list(varset(T)) = assoc_list(var(T), string).
:- pred varset__var_name_list(varset(T)::in, assoc_list(var(T), string)::out)
is det.
-:- func varset__var_name_list(varset(T)) = assoc_list(var(T), string).
-
% Given a list of variable and varset in which some variables have
% no name but some other variables may have the same name,
% return another varset in which every variable has a unique name.
% If necessary, names will have suffixes added on the end;
% the second argument gives the suffix to use.
-:- pred varset__ensure_unique_names(list(var(T))::in,
- string::in, varset(T)::in, varset(T)::out) is det.
-
+ %
:- func varset__ensure_unique_names(list(var(T)), string, varset(T))
= varset(T).
+:- pred varset__ensure_unique_names(list(var(T))::in,
+ string::in, varset(T)::in, varset(T)::out) is det.
% Given a varset and a set of variables, remove the names
% and values of any other variables stored in the varset.
-:- pred varset__select(varset(T)::in, set(var(T))::in, varset(T)::out) is det.
-
+ %
:- func varset__select(varset(T), set(var(T))) = varset(T).
+:- pred varset__select(varset(T)::in, set(var(T))::in, varset(T)::out) is det.
% Given a varset and a list of variables, construct a new varset
% containing one variable for each one in the list (and no others).
% Also return a substitution mapping the selected variables in the
% original varset into variables in the new varset. The relative
% ordering of variables in the original varset is maintained.
+ %
:- pred varset__squash(varset(T)::in, list(var(T))::in,
varset(T)::out, map(var(T), var(T))::out) is det.
% Coerce the types of the variables in a varset.
+ %
+:- func varset__coerce(varset(T)) = varset(U).
:- pred varset__coerce(varset(T)::in, varset(U)::out) is det.
-:- func varset__coerce(varset(T)) = varset(U).
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
:- implementation.
--------------------------------------------------------------------------
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