[m-dev.] Re: zero-arity higher-order function terms and apply/1
Fergus Henderson
fjh at cs.mu.oz.au
Thu Jul 24 17:41:59 AEST 1997
Tyson Richard DOWD, you wrote:
> > compiler/mercury_to_mercury.m:
> > Fix the output of nullary higher-order function insts:
> > previously it would output `(func() = Mode is Det)',
> > but the correct output is `((func) = Mode is Det)'.
>
> You should also modify std_util:type_name to use the
> (func) = Type
> syntax.
Ah, good point.
--
More changes to support nullary higher-order function terms.
library/std_util.m:
Change type_name/1 so that it outputs nullary higher-order
function types correctly.
tests/hard_coded/nullary_ho_func.m:
tests/hard_coded/nullary_ho_func.exp:
Add test case for type_name/1 on nullary h.o. function type.
Index: std_util.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/std_util.m,v
retrieving revision 1.95
diff -u -r1.95 std_util.m
--- std_util.m 1997/07/18 04:42:00 1.95
+++ std_util.m 1997/07/24 07:15:25
@@ -1202,9 +1202,19 @@
TypeName = Name
;
( Name = "func" -> IsFunc = yes ; IsFunc = no ),
- type_arg_names(ArgTypes, IsFunc, ArgTypeNames),
- string__append_list([Name, "(" | ArgTypeNames],
- TypeName)
+ (
+ IsFunc = yes,
+ ArgTypes = [FuncRetType]
+ ->
+ FuncRetTypeName = type_name(FuncRetType),
+ string__append_list(
+ ["((func) = ", FuncRetTypeName, ")"],
+ TypeName)
+ ;
+ type_arg_names(ArgTypes, IsFunc, ArgTypeNames),
+ string__append_list([Name, "(" | ArgTypeNames],
+ TypeName)
+ )
).
:- pred type_arg_names(list(type_info), bool, list(string)).
cvs diff: Diffing .
Index: nullary_ho_func.exp
===================================================================
RCS file: /home/staff/zs/imp/tests/hard_coded/nullary_ho_func.exp,v
retrieving revision 1.1
diff -u -r1.1 nullary_ho_func.exp
--- nullary_ho_func.exp 1997/07/23 15:29:14 1.1
+++ nullary_ho_func.exp 1997/07/24 07:36:45
@@ -4,3 +4,5 @@
apply_nullary_func(F) = 42
Y = apply(G) failed
Z = 42
+type_of(Z) = ((func) = int)
+type_name(type_of(Z)) = ((func) = int)
Index: nullary_ho_func.m
===================================================================
RCS file: /home/staff/zs/imp/tests/hard_coded/nullary_ho_func.m,v
retrieving revision 1.1
diff -u -r1.1 nullary_ho_func.m
--- nullary_ho_func.m 1997/07/23 15:29:16 1.1
+++ nullary_ho_func.m 1997/07/24 07:38:07
@@ -43,5 +43,7 @@
print("Z = "), print(Z), nl
;
print("Y = apply(G) failed"), nl
- ).
+ ),
+ print("type_of(F) = "), print(type_of(F)), nl,
+ print("type_name(type_of(F)) = "), print(type_name(type_of(F))), nl.
--
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