[m-rev.] diff: fix handling of {}/1 constructors

Simon Taylor stayl at cs.mu.OZ.AU
Fri Aug 24 18:38:28 AEST 2001


Estimated hours taken: 1
Branches: main

compiler/type_util.m:
	Allow user-defined types with a single constructor `{}/1' 
	to be treated as no-tag types. Unary tuples aren't treated
	as no-tag types because it would significantly complicate
	the implementation.

	Use more descriptive variable names.

	Simplify some code using std_util__map_maybe.

Index: type_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/type_util.m,v
retrieving revision 1.98
diff -u -u -r1.98 type_util.m
--- type_util.m	2001/08/24 01:39:45	1.98
+++ type_util.m	2001/08/24 05:48:57
@@ -993,23 +993,15 @@
 	% type_constructors_are_no_tag_type/3 is called.
 
 type_constructors_are_no_tag_type(Ctors, Ctor, ArgType, MaybeArgName) :-
-	type_is_single_ctor_single_arg(Ctors, Ctor, MaybeSymName, ArgType),
+	type_is_single_ctor_single_arg(Ctors, Ctor, MaybeArgName0, ArgType),
 	\+ ctor_is_type_info(Ctor),
 
 	% We don't handle unary tuples as no_tag types --
 	% they are rare enough that it's not worth
 	% the implementation effort.
-	unqualify_name(Ctor, Name),
-	Name \= "{}",
+	Ctor \= unqualified("{}"),
 
-	(
-		MaybeSymName = yes(SymName),
-		unqualify_name(SymName, ArgName),
-		MaybeArgName = yes(ArgName)
-	;
-		MaybeSymName = no,
-		MaybeArgName = no
-	).
+	map_maybe(unqualify_name, MaybeArgName0, MaybeArgName).
 
 type_constructors_are_type_info(Ctors) :-
 	type_is_single_ctor_single_arg(Ctors, Ctor, _, _),
@@ -1043,13 +1035,13 @@
 	mercury_private_builtin_module(ModuleName).
 
 :- pred type_is_single_ctor_single_arg(list(constructor), sym_name, 
-	maybe(sym_name), type).
+	maybe(ctor_field_name), type).
 :- mode type_is_single_ctor_single_arg(in, out, out, out) is semidet.
 
-type_is_single_ctor_single_arg(Ctors, Ctor, MaybeSymName, ArgType) :-
+type_is_single_ctor_single_arg(Ctors, Ctor, MaybeArgName, ArgType) :-
 	Ctors = [SingleCtor],
 	SingleCtor = ctor(ExistQVars, _Constraints, Ctor, 
-		[MaybeSymName - ArgType]),
+		[MaybeArgName - ArgType]),
 	ExistQVars = [].
 
 %-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
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