[m-rev.] diff: simplify the rational module a little

Julien Fischer juliensf at cs.mu.OZ.AU
Thu Aug 19 16:03:22 AEST 2004


Estimated hours taken: 0.1
Branches: main

Simplify the rational module a little.

library/rational.m:
	Remove the local type rational.comparison.  We can
	just use builtin.comparison_result instead here.

Julien.

Index: rational.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/rational.m,v
retrieving revision 1.7
diff -u -r1.7 rational.m
--- rational.m	12 Jan 2004 12:46:40 -0000	1.7
+++ rational.m	19 Aug 2004 05:55:42 -0000
@@ -98,19 +98,19 @@

 '<'(R1, R2) :-
 	Cmp = cmp(R1, R2),
-	Cmp = lessthan.
+	Cmp = (<).

 '>'(R1, R2) :-
 	Cmp = cmp(R1, R2),
-	Cmp = greaterthan.
+	Cmp = (>).

 '=<'(R1, R2) :-
 	Cmp = cmp(R1, R2),
-	(Cmp = lessthan ; Cmp = equal).
+	(Cmp = (<) ; Cmp = (=)).

 '>='(R1, R2) :-
 	Cmp = cmp(R1, R2),
-	(Cmp = greaterthan ; Cmp = equal).
+	(Cmp = (>) ; Cmp = (=)).

 rational__rational(Int) = rational_norm(integer(Int), integer__one).

@@ -203,21 +203,16 @@
 	; integer__one
 	).

-:- type comparison
-	--->	equal
-	;	lessthan
-	;	greaterthan.
-
-:- func cmp(rational, rational) = comparison.
+:- func cmp(rational, rational) = comparison_result.

 cmp(R1, R2) = Cmp :-
 	Diff = R1 - R2,
 	( is_zero(Diff) ->
-		Cmp = equal
+		Cmp = (=)
 	; is_negative(Diff) ->
-		Cmp = lessthan
+		Cmp = (<)
 	;
-		Cmp = greaterthan
+		Cmp = (>)
 	).

 :- pred is_zero(rational::in) is semidet.

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