[m-rev.] for review: Added cord.condense/2
Paul Bone
paul at bone.id.au
Mon Jul 1 16:51:57 AEST 2013
For review by anyuone.
Added cord.condense/2
library/cord.m:
Added new predicate and function
NEWS:
Announce change
---
NEWS | 9 +++++++++
library/cord.m | 24 ++++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/NEWS b/NEWS
index d3c6eac..efd5232 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,12 @@
+NEWS since Mercury 13.05.x
+--------------------------
+
+Changes to the Mercury standard library:
+
+* We have added a predicate cord.condense/2 and a function
+ cord.condense/1.
+
+
NEWS for Mercury 13.05.2
------------------------
diff --git a/library/cord.m b/library/cord.m
index a5c2ffa..f0ef725 100644
--- a/library/cord.m
+++ b/library/cord.m
@@ -76,6 +76,13 @@
%
:- func from_list(list(T)) = cord(T).
+ % condense(CordOfCords, Cord):
+ %
+ % `Cord' is the result of concatenating all the elements of `CordOfCords'.
+ %
+:- pred condense(cord(cord(T))::in, cord(T)::out) is det.
+:- func condense(cord(cord(T))) = cord(T).
+
% list(cons(X, C)) = [X | list(C)]
% An O(1) operation.
%
@@ -263,6 +270,23 @@ from_list(Xs) = C :-
%-----------------------------------------------------------------------------%
+condense(empty_cord, empty_cord).
+condense(nonempty_cord(C0), C) :-
+ condense_2(C0, C).
+
+:- pred condense_2(cord_node(cord(T))::in, cord(T)::out) is det.
+
+condense_2(unit_node(C), C).
+condense_2(list_node(C, L), C ++ cord_list_to_cord(L)).
+condense_2(branch_node(Left0, Right0), Left ++ Right) :-
+ condense_2(Left0, Left),
+ condense_2(Right0, Right).
+
+condense(CordOfCords) = Cord :-
+ condense(CordOfCords, Cord).
+
+%-----------------------------------------------------------------------------%
+
list(empty_cord) = [].
list(nonempty_cord(N)) = list_2([N], []).
--
1.8.1.3
More information about the reviews
mailing list