[m-dev.] for review: new mode syntax

Tyson Dowd trd at cs.mu.OZ.AU
Tue Aug 15 17:17:11 AEST 2000


Hi,

Well, if we are going to make . the module qualification operator, and
: the type qualification operator, and :: the mode qualification
operator, then some people suggested that 
	:- mode foo :: bar -> baz. 
might be a bit confusing (does this mean foo is a predicate with an
inline mode, or is this defining a mode called foo?).

So hopefully this will clean up the :- mode (and :- inst) syntax a bit
in preparation for such changes.

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


Estimated hours taken: 3

Make the syntax for defining modes and insts similar to type equivalence.

Old syntax:
	:- inst foo = someinstdefn.
	:- mode foo :: someinst -> someotherinst.

New syntax:
	:- inst foo == someinstdefn.
	:- mode foo == someinst >> someotherinst.

The old syntax is still supported.  For `::' and `->' it may eventually
be phased out (but it doesn't cause many problems apart from possible
confusion of users, so it's a low priority).

In the case of `:- inst' we could already use `==' or `=', however we
now make `==' the standard syntax.  Again, we support both and probably 
will for quite some time.

NEWS:
	Mention these changes. 

compiler/prog_io.m:
	Make `==' the standard operator for `:- inst <InstDefn>.'
	declarations.

	Make `==' and `>>' the standard operators for 
	`:- mode foo == someinst >> someotherinst'.
	`::' and `->' are still supported.

compiler/prog_io_util.m:
	Make `>>' the standard operator for inline mode declarations.
	`->' is still supported.

doc/reference_manual.texi:
	Update the syntax in the reference manual.
	Mention that `::' and `->' is deprecated.

tests/valid/Mmakefile:
tests/valid/mode_syntax.m:
	Add a new test of the new syntax.

compiler/fact_table.m:
	Fix a typo (missing quote) in the verbose messages for fact tables.


Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.168
diff -u -r1.168 NEWS
--- NEWS	2000/05/24 05:18:25	1.168
+++ NEWS	2000/08/15 07:02:48
@@ -24,6 +24,20 @@
 * We've generalized the higher-order term syntax a little:
   in `Foo(Args)', we now allow Foo to be any term, not just
   a variable.
+
+* The syntax for defining insts and modes has been changed to be 
+  more uniform.  For example, the old syntax
+
+  	:- inst myfree = free.
+  	:- mode out :: myfree -> ground.
+
+  would now be written
+
+  	:- inst myfree == free.
+  	:- mode out == myfree >> ground.
+
+  The old syntax is still accepted but is deprecated.  Support for it may
+  eventually be dropped.
  
 Changes to the standard library:
 
Index: compiler/prog_io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io.m,v
retrieving revision 1.189
diff -u -r1.189 prog_io.m
--- compiler/prog_io.m	2000/04/22 07:11:57	1.189
+++ compiler/prog_io.m	2000/08/14 06:00:09
@@ -2003,6 +2003,10 @@
 
 	% Parse a `:- inst <InstDefn>.' declaration.
 	%
+	% `==' is the correct operator to use, although we accept
+	% `=' as well.  Since `=' was once the standard operator, make
+	% sure warnings are given before it is phased out.
+	%
 :- pred parse_inst_decl(module_name, varset, term, maybe1(item)).
 :- mode parse_inst_decl(in, in, in, out) is det.
 parse_inst_decl(ModuleName, VarSet, InstDefn, Result) :-
@@ -2032,7 +2036,7 @@
 		convert_inst_defn(ModuleName, H, Body1, R),
 		process_maybe1(make_inst_defn(VarSet, Condition), R, Result)
 	;
-		Result = error("`=' expected in `:- inst' definition", InstDefn)
+		Result = error("`==' expected in `:- inst' definition", InstDefn)
 	).
 		% we should check the condition for errs
 		% (don't bother at the moment, since we ignore
@@ -2160,14 +2164,31 @@
 		parse_mode_decl_pred(ModuleName, VarSet, ModeDefn, Result)
 	).
 
-	% People never seem to remember what the right operator to use in a
-	% `:- mode' declaration is, so the syntax is forgiving.  We allow
-	% `::', the standard one which has the right precedence, but we
-	% also allow `==' just to be nice.
+	% People never seemed to remember what the right operator to use
+	% in a `:- mode' declaration is, so the syntax is accepted both
+	% `::' and `==', with `::' formerly the standard operator.  
+	%
+	%	% Old syntax
+	% :- mode foo :: someinst -> someotherinst.
+	%
+	% But using `==' was a pain, because the precedence of `->' was
+	% too high.  We now accept `>>' as an alternative to `->', and
+	% `==' is now the standard operator to use in a `:- mode'
+	% declaration.  This is part of a long term plan to free up
+	% `::' as an operator so we can use it for mode qualification.
+	%
+	%	% New syntax
+	% :- mode foo == someinst >> someotherinst.
+	%
+	% We still support `::' in mode declarations for backwards
+	% compatibility, but it might be removed one day.
+	% Before phasing it out, a deprecated syntax warning should be
+	% given for a version or two.
+	%
 :- pred mode_op(term, term, term).
 :- mode mode_op(in, out, out) is semidet.
 mode_op(term__functor(term__atom(Op), [H, B], _), H, B) :-
-	( Op = "::" ; Op = "==" ).
+	( Op = "==" ; Op = "::" ).
 
 :- pred convert_mode_defn(module_name, term, term, maybe1(mode_defn)).
 :- mode convert_mode_defn(in, in, in, out) is det.
Index: compiler/prog_io_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io_util.m,v
retrieving revision 1.16
diff -u -r1.16 prog_io_util.m
--- compiler/prog_io_util.m	1999/12/27 11:07:29	1.16
+++ compiler/prog_io_util.m	2000/08/14 06:00:17
@@ -221,9 +221,26 @@
 	convert_mode(H0, H),
 	convert_mode_list(T0, T).
 
+
+	% 
+	% The new operator for mode declarations is >>.
+	% Previously we used ->, but this required a high-precedence
+	% operator such as :: for the :- mode delcaration.
+	%
+	% Using >> allows us to use == for the :- mode declaration.
+	%
+	% Eventually we can stop supporting :: and -> in :- mode
+	% declarations altogether.
+	%
 convert_mode(Term, Mode) :-
 	(
-		Term = term__functor(term__atom("->"), [InstA, InstB], _Context)
+		( 
+			Term = term__functor(term__atom(">>"), 
+				[InstA, InstB], _)
+		;
+			Term = term__functor(term__atom("->"),
+				[InstA, InstB], _)
+		)
 	->
 		convert_inst(InstA, ConvertedInstA),
 		convert_inst(InstB, ConvertedInstB),
Index: doc/reference_manual.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.184
diff -u -r1.184 reference_manual.texi
--- doc/reference_manual.texi	2000/08/03 06:18:21	1.184
+++ doc/reference_manual.texi	2000/08/07 04:57:46
@@ -1525,7 +1525,7 @@
 to declare names for instantiatedness trees using declarations such as
 
 @example
-:- inst listskel = bound( [] ; [free | listskel] ).
+:- inst listskel == bound( [] ; [free | listskel] ).
 @end example
 
 This instantiatedness tree describes lists
@@ -1547,27 +1547,31 @@
 with the constraint that no node of the type tree
 is transformed from bound to free.
 Mercury allows the user to specify mode mappings directly
-by expressions such as @code{inst1 -> inst2},
+by expressions such as @code{inst1 >> inst2},
 or to give them a name using declarations such as
 
 @example
-:- mode m :: inst1 -> inst2.
+:- mode m == inst1 >> inst2.
 @end example
 
+It is also possible to write mode declarations using @code{::}
+and @code{->} instead of @code{==} and @code{>>} respectively,
+however this syntax is deprecated and may not be supported in future.
+
 Two standard shorthand modes are provided,
 corresponding to the standard notions of inputs and outputs:
 
 @example
-:- mode in :: ground -> ground.
-:- mode out :: free -> ground.
+:- mode in == ground >> ground.
+:- mode out == free >> ground.
 @end example
 
 Prolog fans who want to use the symbols @samp{+} and @samp{-}
 can do so by simply defining them using a mode declaration:
 
 @example
-:- mode (+) :: in.
-:- mode (-) :: out.
+:- mode (+) == in.
+:- mode (-) == out.
 @end example
 
 These two modes are enough for most functions and predicates.
@@ -1586,19 +1590,19 @@
 :- type operation
         --->    lookup(key, data)
         ;       set(key, data).
-:- inst request =
+:- inst request ==
         bound(  lookup(ground, free)
         ;       set(ground, ground)
         ).
-:- mode create_request :: free -> request.
-:- mode satisfy_request :: request -> ground.
+:- mode create_request == free >> request.
+:- mode satisfy_request == request >> ground.
 @end example
 
 @samp{inst} and @samp{mode} declarations can be parametric.
 For example, the following declaration 
 
 @example
-:- inst listskel(Inst) = bound( [] ; [Inst | listskel(Inst)] ).
+:- inst listskel(Inst) == bound( [] ; [Inst | listskel(Inst)] ).
 @end example
 
 @noindent
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/valid/Mmakefile,v
retrieving revision 1.67
diff -u -r1.67 Mmakefile
--- tests/valid/Mmakefile	2000/08/04 23:58:46	1.67
+++ tests/valid/Mmakefile	2000/08/14 00:08:47
@@ -97,6 +97,7 @@
 	loop_in_disj.m \
 	middle_rec_labels.m \
 	modes_bug.m \
+	mode_syntax.m \
 	module_a.m \
 	module_b.m \
 	module_c.m \
Index: tests/valid/mode_syntax.m
===================================================================
RCS file: mode_syntax.m
diff -N mode_syntax.m
--- /dev/null	Tue May 16 14:50:59 2000
+++ mode_syntax.m	Mon Aug 14 10:08:17 2000
@@ -0,0 +1,54 @@
+%
+% This is a test of the mode syntax.
+%
+% The official new syntax is:
+%
+% 	:- mode foo == bar >> baz.
+%
+% We also accept:
+%
+% 	:- mode foo :: bar -> baz.
+%
+% which is the old syntax.
+%
+% And finally we accept mixing them up:
+% 		
+% 	:- mode foo == (bar -> baz).
+% 	:- mode foo :: bar >> baz.
+%
+% You can also use `bar >> baz' inline after a mode qualifier.
+%
+
+
+:- module mode_syntax.
+:- interface.
+:- import_module list.
+
+:- mode my_input_list_skel == list_skel >> list_skel.
+:- mode my_output_list_skel :: free >> list_skel.
+:- mode my_list_skel_output == (list_skel -> ground).
+:- mode another_mode :: list_skel -> list_skel.
+
+:- pred p is semidet.
+
+:- pred p2(list(T)::my_output_list_skel) is nondet.
+
+:- implementation.
+
+:- pred q(list(T)::list_skel >> list_skel /* my_input_list_skel */).
+:- pred r(list(T)::my_output_list_skel).
+
+q(_X) :- q([]).
+r(X) :- r(X).
+
+p :-
+	r(X),
+	q(X).
+
+p2(X) :-
+	r(X),
+	q(X)
+	;
+	r(X),
+	q(X).
+


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