for review: use '=>' for existential type class constraints
Fergus Henderson
fjh at cs.mu.OZ.AU
Thu Oct 29 18:13:45 AEDT 1998
DJ, could you please review this one?
--------------------
Estimated hours taken: 2
Change the syntax for existential type class constraints to use
`=>' instead of `&'.
We eventually decided that `=>' was better, even though semantically
speaking it's more like conjunction than implication, because of the
symmetry with `<=' for universal type class constraints, and because
the precedence of `=>' matches what we want.
[However, the associativity might not.]
compiler/prog_io.m:
Update the code that parses existential type class constraints.
compiler/mercury_to_mercury.m:
Update the code that prints existential type class constraints.
tests/hard_coded/typeclasses/existential_type_classes.m:
Update the test case that tests existential type class constraints.
Also add a test of passing typeclass_infos to C code.
Index: compiler/mercury_to_mercury.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_to_mercury.m,v
retrieving revision 1.147
diff -u -r1.147 mercury_to_mercury.m
--- mercury_to_mercury.m 1998/09/22 16:13:32 1.147
+++ mercury_to_mercury.m 1998/10/28 06:59:23
@@ -1186,14 +1186,14 @@
io__write_string("(")
),
- % we need to quote ';'/2, '{}'/2, '&'/2, and 'some'/2
+ % we need to quote ';'/2, '{}'/2, '=>'/2, and 'some'/2
{ list__length(Args, Arity) },
(
{ Arity = 2 },
{ Name = unqualified(";")
; Name = unqualified("{}")
; Name = unqualified("some")
- ; Name = unqualified("&")
+ ; Name = unqualified("=>")
}
->
io__write_string("{ ")
@@ -1216,7 +1216,7 @@
{ Name = unqualified(";")
; Name = unqualified("{}")
; Name = unqualified("some")
- ; Name = unqualified("&")
+ ; Name = unqualified("=>")
}
->
io__write_string(" }")
@@ -1224,7 +1224,7 @@
[]
),
- mercury_output_class_constraint_list(Constraints, VarSet, "&"),
+ mercury_output_class_constraint_list(Constraints, VarSet, "=>"),
(
{ ExistQVars = [] }
->
@@ -1439,7 +1439,7 @@
mercury_output_class_context(ClassContext, ExistQVars, VarSet) -->
{ ClassContext = constraints(UnivCs, ExistCs) },
- mercury_output_class_constraint_list(ExistCs, VarSet, "&"),
+ mercury_output_class_constraint_list(ExistCs, VarSet, "=>"),
( { ExistQVars = [], ExistCs = [] } ->
[]
;
Index: compiler/prog_io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io.m,v
retrieving revision 1.175
diff -u -r1.175 prog_io.m
--- prog_io.m 1998/07/25 13:36:23 1.175
+++ prog_io.m 1998/10/28 06:53:27
@@ -1035,7 +1035,7 @@
parse_decl_attribute("semipure", [Decl], purity(semipure), Decl).
parse_decl_attribute("<=", [Decl, Constraints],
constraints(univ, Constraints), Decl).
-parse_decl_attribute("&", [Decl, Constraints],
+parse_decl_attribute("=>", [Decl, Constraints],
constraints(exist, Constraints), Decl).
parse_decl_attribute("some", [TVars, Decl],
quantifier(exist, TVarsList), Decl) :-
@@ -1075,7 +1075,7 @@
attribute_description(quantifier(exist, _), "existential quantifier (`some')").
attribute_description(constraints(univ, _), "type class constraint (`<=')").
attribute_description(constraints(exist, _),
- "existentially quantified type class constraint (`&')").
+ "existentially quantified type class constraint (`=>')").
%-----------------------------------------------------------------------------%
@@ -1432,7 +1432,7 @@
term__contains_var_list(Args, Var),
\+ list__member(Var, ExistQVars)
->
- Result = error("type variables in class constraints introduced with `&' must be explicitly existentially quantified using `some'",
+ Result = error("type variables in class constraints introduced with `=>' must be explicitly existentially quantified using `some'",
Body)
;
(
@@ -1658,15 +1658,17 @@
% 1. universal quantifiers all 950
% 2. existential quantifiers some 950
% 3. universal constraints <= 920
- % 4. existential constraints & 1020 [*]
+ % 4. existential constraints => 920 [*]
% 5. the decl itself pred or func 800
%
% When we reach here, Attributes0 contains declaration attributes
% in the opposite order -- innermost to outermost -- so we reverse
% them before we start.
%
- % [*] Note that the precedence of `&' is not quite what we want for
- % this purpose -- the user will have to put in explicit parentheses.
+ % [*] Note that the semantic meaning of `=>' is not quite
+ % the same as implication; logically speaking it's more
+ % like conjunction. Oh well, at least it has the right
+ % precedence.
%
% In theory it could make sense to allow the order of 2 & 3 to be
% swapped, or (in the case of multiple constraints & multiple
@@ -1763,7 +1765,7 @@
get_existential_constraints_from_term(ModuleName, PredType0, PredType,
MaybeExistentialConstraints) :-
(
- PredType0 = term__functor(term__atom("&"),
+ PredType0 = term__functor(term__atom("=>"),
[PredType1, ExistentialConstraints], _)
->
PredType = PredType1,
Index: tests/hard_coded/typeclasses/existential_type_classes.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/typeclasses/existential_type_classes.m,v
retrieving revision 1.2
diff -u -r1.2 existential_type_classes.m
--- existential_type_classes.m 1998/07/08 20:59:12 1.2
+++ existential_type_classes.m 1998/10/29 06:57:56
@@ -27,11 +27,11 @@
% my_univ_value(Univ):
% returns the value of the object stored in Univ.
-:- some [T] (func my_univ_value(univ) = T & fooable(T)).
+:- some [T] func my_univ_value(my_univ) = T => fooable(T).
-:- some [T] (func call_my_univ_value(univ) = T & fooable(T)).
+:- some [T] func call_my_univ_value(my_univ) = T => fooable(T).
-:- some [T] (func my_exist_t = T & fooable(T)).
+:- some [T] func my_exist_t = T => fooable(T).
:- pred int_foo(int::in, int::out) is det.
int_foo(X, 2*X).
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list