[m-rev.] for review: improvements for library/ops.m

Simon Taylor stayl at cs.mu.OZ.AU
Sun Nov 4 20:05:59 AEDT 2001


On 04-Nov-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 04-Nov-2001, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> > 	Move some items which are really just implementation
> > 	details to a less prominent position in the interface.
> 
> This bit I'm not quite so happy with.
> 
> Firstly, I don't consider those items to be implementation details.

They aren't used in the interface to the ops_table.
 
> Secondly, the change has been applied inconsistently; why move
> the definition of `ops__class', but not move the definition of
> `ops__specifier'? 

The documentation of `ops__specifier' was the best way to explain
`ops__assoc', which is used in the interface to the ops__table.

> These two types are very closely related --
> they are just two different ways of representing the same
> information -- so the definitions of these two types should
> definitely remain together.

OK.

> If you want to order it differently, the module's interface could be
> divided into three sections:
> 	- one for the stuff about the different kinds of operators
> 	  (ops__specifier, ops__class, ops__assoc, and
> 	  ops__op_specifier_to_class).

> 	- one for the stuff about operator priorities
> 	  (the ops__priority type and the ops__max_priority predicate --
> 	  which, incidentally, ought to be a function now...)

I think ops__max_priority is related to the operator table -- if we allowed
user-defined operator tables, there would be no reason to restrict them
to the same range of priorities as the Prolog operators.

> 	- one for the operator table and related procedures
> (not necessarily in that order).


--- NEWS	2001/11/04 08:23:39	1.1
+++ NEWS	2001/11/04 08:23:47
@@ -92,6 +92,9 @@
 
 * We've added a predicate version of `set__fold'.
 
+* We've added function versions of `ops__init_op_table'
+  and `ops__max_priority'.
+
 * We've added some functions to the term_io module to return printable
   representations of term components as strings.
 
--- ops.m	2001/11/04 06:32:48	1.1
+++ ops.m	2001/11/04 08:21:42
@@ -18,27 +18,6 @@
 :- module ops.
 :- interface.
 
-	% An ops__specifier describes what structure terms
-	% constructed with an operator are allowed to take.
-	% `f' represents the operator and `x' and `y' represent arguments.
-	% `x' represents an argument whose priority must be
-	% strictly lower that that of the operator.
-	% `y' represents an argument whose priority is
-	% lower or equal to that of the operator.
-	% For example, `yfx' indicates a left-associative infix operator,
-	% while `xfy' indicates a right-associative infix operator.
-:- type ops__specifier
-	--->	fx ; fy ; xf ; yf ; xfx ; yfx ; xfy ; fxx ; fxy ; fyx.
-
-:- type ops__assoc
-	--->	x ; y.
-
-	% Operators with a low "priority" bind more tightly than those
-	% with a high "priority". For example, given that `+' has
-	% priority 500 and `*' has priority 400, the term `2 * X + Y'
-	% would parse as `(2 * X) + Y'.
-:- type ops__priority == int.
-
 :- type ops__table.
 
 	% create an ops_table with the standard Mercury operators.
@@ -49,23 +28,24 @@
 
 	% check whether a string is the name of an infix operator,
 	% and if it is, return its precedence and associativity.
-:- pred ops__lookup_infix_op(ops__table, string, int, ops__assoc, ops__assoc).
+:- pred ops__lookup_infix_op(ops__table, string, ops__priority,
+					ops__assoc, ops__assoc).
 :- mode ops__lookup_infix_op(in, in, out, out, out) is semidet.
 
 	% check whether a string is the name of a prefix operator,
 	% and if it is, return its precedence and associativity.
-:- pred ops__lookup_prefix_op(ops__table, string, int, ops__assoc).
+:- pred ops__lookup_prefix_op(ops__table, string, ops__priority, ops__assoc).
 :- mode ops__lookup_prefix_op(in, in, out, out) is semidet.
 
 	% check whether a string is the name of a binary prefix operator,
 	% and if it is, return its precedence and associativity.
 :- pred ops__lookup_binary_prefix_op(ops__table, string,
-					int, ops__assoc, ops__assoc).
+					ops__priority, ops__assoc, ops__assoc).
 :- mode ops__lookup_binary_prefix_op(in, in, out, out, out) is semidet.
 		
 	% check whether a string is the name of a postfix operator,
 	% and if it is, return its precedence and associativity.
-:- pred ops__lookup_postfix_op(ops__table, string, int, ops__assoc).
+:- pred ops__lookup_postfix_op(ops__table, string, ops__priority, ops__assoc).
 :- mode ops__lookup_postfix_op(in, in, out, out) is semidet.
 
 	% check whether a string is the name of an operator
@@ -76,11 +56,36 @@
 	% Note that due to Prolog tradition, the priority numbers
 	% are backwards: higher numbers mean lower priority
 	% and lower numbers mean higher priority.  Sorry...
+:- func ops__max_priority = ops__priority.
+
 :- pred ops__max_priority(ops__priority).
 :- mode ops__max_priority(out) is det.
 
 %-----------------------------------------------------------------------------%
 
+	% Operators with a low "priority" bind more tightly than those
+	% with a high "priority". For example, given that `+' has
+	% priority 500 and `*' has priority 400, the term `2 * X + Y'
+	% would parse as `(2 * X) + Y'.
+:- type ops__priority == int.
+
+%-----------------------------------------------------------------------------%
+
+	% An ops__specifier describes what structure terms
+	% constructed with an operator are allowed to take.
+	% `f' represents the operator and `x' and `y' represent arguments.
+	% `x' represents an argument whose priority must be
+	% strictly lower that that of the operator.
+	% `y' represents an argument whose priority is
+	% lower or equal to that of the operator.
+	% For example, `yfx' indicates a left-associative infix operator,
+	% while `xfy' indicates a right-associative infix operator.
+:- type ops__specifier
+	--->	fx ; fy ; xf ; yf ; xfx ; yfx ; xfy ; fxx ; fxy ; fyx.
+
+:- type ops__assoc
+	--->	x ; y.
+
 :- type ops__class
 	--->	infix(ops__assoc, ops__assoc)
 	;	prefix(ops__assoc)
@@ -242,6 +247,7 @@
 ops__init_op_table(ops__table).
 ops__init_op_table = ops__table.
 
-ops__max_priority(1200).
+ops__max_priority(ops__max_priority).
+ops__max_priority = 1200.
 
 %-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
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