[m-dev.] diff: add fst/snd to library

Peter Ross petdr at cs.mu.OZ.AU
Fri Aug 20 14:26:43 AEST 1999


Hi,

I will check this change in at the end of the day, unless anyone has any
objections.

Pete.

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


Estimated hours taken: 0.5

library/std_util.m:
    Add functional and logical versions of fst and snd for the pair data
    structure.


Index: std_util.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/std_util.m,v
retrieving revision 1.153
diff -u -r1.153 std_util.m
--- std_util.m	1999/08/12 09:58:46	1.153
+++ std_util.m	1999/08/20 04:24:04
@@ -111,6 +111,14 @@
 :- type pair(T1, T2)	--->	(T1 - T2).
 :- type pair(T)		==	pair(T,T).
 
+	% 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.
+
 %-----------------------------------------------------------------------------%
 
 % solutions/2 collects all the solutions to a predicate and
@@ -460,6 +468,14 @@
 
 pair(X, Y, X-Y).
 ****/
+fst(X-_Y) = X.
+fst(P,X) :-
+	X = fst(P).
+
+snd(_X-Y) = Y.
+snd(P,X) :-
+	X = snd(P).
+
 
 maybe_pred(Pred, X, Y) :-
 	(

----
 +----------------------------------------------------------------------+
 | Peter Ross      M Sci/Eng Melbourne Uni                              |
 | petdr at cs.mu.oz.au  WWW: www.cs.mu.oz.au/~petdr/ ph: +61 3 9344 9158  |
 +----------------------------------------------------------------------+
--------------------------------------------------------------------------
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