[m-dev.] diff: add two functions to tree.m

Tyson Dowd trd at cs.mu.OZ.AU
Wed Jul 26 13:06:42 AEST 2000


Hi,

This is the first in a series of diffs to be migrated over from the `p7'
compiler where work was done on the .NET backend.

I'm going to start with the very boring diffs to try to minimize the
final diff and cut down on any merging I have to do from now on.

===================================================================


Estimated hours taken: 0.3

compiler/tree.m:
	Add a functional version of tree__flatten.

	Add tree__list, which creates trees from lists of trees.
	(using list syntax is much more readable than creating lots of
	branching trees).


Index: tree.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/tree.m,v
retrieving revision 1.12
diff -u -r1.12 tree.m
--- tree.m	1999/06/16 00:35:47	1.12
+++ tree.m	2000/07/26 02:45:54
@@ -23,6 +23,11 @@
 			;	node(T)
 			;	tree(tree(T), tree(T)).
 
+:- func tree__flatten(tree(T)) =  list(T).
+
+	% Make a tree from a list of trees.
+:- func tree__list(list(tree(T))) = tree(T).
+
 :- pred tree__flatten(tree(T), list(T)).
 :- mode tree__flatten(in, out) is det.
 
@@ -35,6 +40,11 @@
 %-----------------------------------------------------------------------------%
 
 :- implementation.
+
+tree__flatten(T) = L :- tree__flatten(T, L).
+
+tree__list([]) = empty.
+tree__list([X | Xs]) = tree(X, tree__list(Xs)).
 
 tree__flatten(T, L) :-
 	tree__flatten_2(T, [], L).


-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't everyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list