[m-rev.] for review: make ':' into a type qualifier
Julien Fischer
juliensf at cs.mu.OZ.AU
Thu Sep 22 22:10:11 AEST 2005
Estimated hours taken: 2
Branches: main
Make ':' into an infix type qualification operator, equivalent to `with_type`.
compiler/prog_io.m:
Handle type qualifications in pred and func declarations that use ':'.
compiler/superhomogeneous.m:
Handle type qualifications using ':' in clauses.
library/ops.m:
Change the precedence of ':' so that it is identical to `with_type`.
doc/reference_manual.texi:
Update the list of operators.
Update the section on explicit type qualification expressions.
tests/hard-coded/type_qual.m:
Use the new syntax in this test case.
(There are lots of other test cases that exercise the old syntax.)
NEWS:
Mention that ':' is now the type qualification operator.
Julien.
Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.386
diff -u -r1.386 NEWS
--- NEWS 13 Sep 2005 05:47:15 -0000 1.386
+++ NEWS 22 Sep 2005 10:02:09 -0000
@@ -9,7 +9,7 @@
* We now have support for optional module initialisation.
* We now have support for impure module-local mutable variables.
* Support for the old-style lambda, mode and pragma syntax has been removed.
-* `:' is now longer supported as a module qualifier.
+* ':' is now the type qualification operator, not a module qualifier.
Changes to the Mercury standard library:
* We have added an `injection' module, for reversible maps that are injective.
Index: compiler/prog_io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io.m,v
retrieving revision 1.249
diff -u -r1.249 prog_io.m
--- compiler/prog_io.m 12 Sep 2005 08:20:26 -0000 1.249
+++ compiler/prog_io.m 21 Sep 2005 07:43:12 -0000
@@ -2378,8 +2378,12 @@
get_with_type(Body0, Body, Result) :-
(
- Body0 = term__functor(term__atom("with_type"),
- [Body1, Type1], _)
+ Body0 = term__functor(TypeQualifier, [Body1, Type1], _),
+ (
+ TypeQualifier = term.atom("with_type")
+ ;
+ TypeQualifier = term.atom(":")
+ )
->
Body = Body1,
parse_type(Type1, Result0),
Index: compiler/superhomogeneous.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/superhomogeneous.m,v
retrieving revision 1.5
diff -u -r1.5 superhomogeneous.m
--- compiler/superhomogeneous.m 13 Sep 2005 03:25:42 -0000 1.5
+++ compiler/superhomogeneous.m 22 Sep 2005 08:44:21 -0000
@@ -398,7 +398,11 @@
substitute_state_var_mappings(Args1, Args, !VarSet, !SInfo, !IO),
(
% Handle explicit type qualification.
- F = term__atom("with_type"),
+ (
+ F = term__atom("with_type")
+ ;
+ F = term__atom(":")
+ ),
Args = [RVal, DeclType0]
->
% DeclType0 is a prog_term, but it is really a type so we coerce it
Index: doc/reference_manual.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.327
diff -u -r1.327 reference_manual.texi
--- doc/reference_manual.texi 16 Sep 2005 05:42:53 -0000 1.327
+++ doc/reference_manual.texi 21 Sep 2005 07:51:43 -0000
@@ -424,6 +424,7 @@
@@ xfx 90
^ xfy 99
^ fx 100
+: yfx 120
`@var{op}` yfx 120 @footnote{Operator term (@pxref{Terms}).}
** xfy 200
- fx 200
@@ -446,7 +447,6 @@
aditi_bottom_up fx 500
aditi_top_down fx 500
.. xfx 550
-: yfx 600
:= xfx 650
=^ xfx 650
< xfx 700
@@ -1483,14 +1483,7 @@
An explicit type qualification expression is a term of the form
@example
-with_type(@var{Term}, @var{Type})
- at end example
-
- at noindent
-or equivalently, as it is more commonly written,
-
- at example
- at var{Term} `with_type` @var{Type}
+ at var{Term} : @var{Type}
@end example
@noindent
@@ -1502,6 +1495,20 @@
Apart from that, the meaning of an explicit type qualification
expression is just the same as the specified @var{Term}.
+Currently we also support the following alternative syntax for
+type qualification:
+
+ at example
+with_type(@var{Term}, @var{Type})
+ at end example
+
+ at noindent
+or equivalently, as it is more commonly written,
+
+ at example
+ at var{Term} `with_type` @var{Type}
+ at end example
+
@node Variable scoping
@section Variable scoping
Index: library/ops.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/ops.m,v
retrieving revision 1.52
diff -u -r1.52 ops.m
--- library/ops.m 13 Sep 2005 03:25:42 -0000 1.52
+++ library/ops.m 21 Sep 2005 07:32:30 -0000
@@ -260,7 +260,7 @@
ops__op_table("/", after, yfx, 400). % standard ISO Prolog
ops__op_table("//", after, yfx, 400). % standard ISO Prolog
ops__op_table("/\\", after, yfx, 500). % standard ISO Prolog
-ops__op_table(":", after, yfx, 600). % `xfy' in ISO Prolog
+ops__op_table(":", after, yfx, 120). % Mercury extension
ops__op_table(":-", after, xfx, 1200). % standard ISO Prolog
ops__op_table(":-", before, fx, 1200). % standard ISO Prolog
ops__op_table("::", after, xfx, 1175). % Mercury extension
Index: tests/hard_coded/type_qual.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/type_qual.m,v
retrieving revision 1.3
diff -u -r1.3 type_qual.m
--- tests/hard_coded/type_qual.m 7 Jan 2002 15:14:50 -0000 1.3
+++ tests/hard_coded/type_qual.m 21 Sep 2005 07:57:12 -0000
@@ -1,4 +1,4 @@
-% Test the use of explicit type qualification using the `with_type` operator.
+% Test the use of explicit type qualification using the : operator.
:- module type_qual.
:- interface.
@@ -12,7 +12,7 @@
main -->
test1,
- test2([] `with_type` list(io__state)),
+ test2([] : list(io__state)),
test3,
test4,
test5(yes),
@@ -22,16 +22,16 @@
:- pred test1(io__state::di, io__state::uo) is det.
test1 -->
- io__read(X `with_type` io__read_result(int)),
+ io__read(X : io__read_result(int)),
io__write(X),
nl.
:- pred test2(T::in, io__state::di, io__state::uo) is det.
test2(X) -->
- io__write(type_of(X `with_type` T)),
+ io__write(type_of(X : T)),
nl,
- io__write(type_of(_ `with_type` list(T))),
+ io__write(type_of(_ : list(T))),
nl.
:- pred test3(io__state::di, io__state::uo) is det.
@@ -46,10 +46,10 @@
:- pred test4(io__state::di, io__state::uo) is det.
test4 -->
- { List = build_list `with_type` TypeOfList },
+ { List = build_list : TypeOfList },
io__write(type_of(List)), nl,
io__write(List), nl,
- { EmptyList = [] `with_type` TypeOfList },
+ { EmptyList = [] : TypeOfList },
io__write(type_of(EmptyList)), nl,
io__write(EmptyList), nl.
@@ -57,13 +57,13 @@
% Test use of same type variable in different clauses.
test5(yes) -->
- { _ = [1, 2, 3] `with_type` T },
- { Y = [] `with_type` T },
+ { _ = [1, 2, 3] : T },
+ { Y = [] : T },
io__write(type_of(Y)), nl,
io__write(Y), nl.
test5(no) -->
- { _ = ["1", "2", "3"] `with_type` T },
- { Y = [] `with_type` T },
+ { _ = ["1", "2", "3"] : T },
+ { Y = [] : T },
io__write(type_of(Y)), nl,
io__write(Y), nl.
@@ -72,7 +72,7 @@
test6 -->
(
{
- X = type_of([] `with_type` list(int))
+ X = type_of([] : list(int))
<=>
X = type_of([1, 2, 3])
}
@@ -82,9 +82,9 @@
io__write_string("bi-implication failed\n")
).
-empty_list = [] `with_type` list(int).
+empty_list = [] : list(int).
-empty([] `with_type` list(int)).
+empty([] : list(int)).
:- some [T] func build_list = list(T).
@@ -94,6 +94,6 @@
:- pred map_search(my_map(K, V)::in, int::in, V::out) is semidet.
-map_search(Map `with_type` map(int, V), Key `with_type` int,
- Value `with_type` V) :-
+map_search(Map : map(int, V), Key : int,
+ Value : V) :-
map__search(Map, Key, Value).
--------------------------------------------------------------------------
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