[m-dev.] for review: improve higher-order syntax

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Feb 16 19:34:40 AEDT 2000


On 13-Feb-2000, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> If I read this right, you can use an operator term as a HO "functor" by
> wrapping it in parenthesis like so:
> 
> 	(F1 `compose` F2)(Arg)

That's correct.

> It would be helpful to explicitly mention this.

Shall do.

> > +any intervening whitespace by an open parenthesis (i.e. an open_ct token),
> >  a sequence of argument terms separated by commas, and a close
> > -parenthesis.  A higher-order term is equivalent to a compound term
> > +parenthesis.  A higher-order term is equivalent to a simple compound term
> >  whose functor is the empty name, and whose arguments are the 
> >  the variable followed by the arguments of the higher-order term.
> 
> The word "variable" here is no longer appropriate.

Fixed.

> >  That is, a term such as @code{Var(Arg1, @dots{}, ArgN)} is
> > -parsed as @code{''(Var, Arg1, @dots{}, ArgN)},
> > +parsed as @code{''(Var, Arg1, @dots{}, ArgN)}.
> 
> And probably here, too.

Fixed.

I've also added a test case, and mentioned the change
in the NEWS file.  Here's a relative diff of
the log message, diffs for the change to NEWS
and for the test case, and both full and relative
diffs for the updated version of my changes to the
language reference manual.

I'll go ahead and commit this.

--- CHANGES.old	Wed Feb 16 19:29:52 2000
+++ CHANGES	Wed Feb 16 19:29:48 2000
@@ -1,5 +1,5 @@
 
-Estimated hours taken: 1.5
+Estimated hours taken: 2.5
 
 Generalize the higher-order term syntax:
 in `Foo(Args)', allow Foo to be any term,
@@ -10,4 +10,11 @@
 
 library/parser.m:
 	Implement the new higher-order term syntax.
+
+tests/hard_coded/Mmakefile:
+tests/hard_coded/higher_order_syntax2.m:
+tests/hard_coded/higher_order_syntax2.exp:
+
+NEWS:
+	Mention this change.
 


Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.162
diff -u -d -r1.162 NEWS
--- NEWS	2000/02/16 08:17:48	1.162
+++ NEWS	2000/02/16 08:20:29
@@ -20,6 +20,10 @@
   For example:
   	GetEvens = list__filter_map(
 		(func(X) = X is semidet :- X mod 2 = 0)).
+
+* 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.
  
 Changes to the standard library:
 
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.76
diff -u -d -r1.76 Mmakefile
--- tests/hard_coded/Mmakefile	2000/02/04 03:45:51	1.76
+++ tests/hard_coded/Mmakefile	2000/02/16 08:28:04
@@ -57,6 +57,7 @@
 	ground_dd \
 	higher_order_func_test \
 	higher_order_syntax \
+	higher_order_syntax2 \
 	higher_order_type_manip \
 	ho_func_reg \
 	ho_order \
==============================
tests/hard_coded/higher_order_syntax2.exp
==============================
Result = 7
Result2 = 11
==============================
tests/hard_coded/higher_order_syntax2.m
==============================
:- module higher_order_syntax2.
:- interface.
:- import_module io.

:- pred main(io__state::di, io__state::uo) is det.

:- implementation.
:- import_module int, std_util.

:- func curry((func(V_3, V_2) = V_1)) = ((func V_3) = ((func V_2) = V_1)).
:- func uncurry(((func V_3) = ((func V_2) = T4)), V_3, V_2) = T4.
:- func id((func(V_3, V_2) = T4)) = (func(V_3, V_2) = T4).
:- func pplus(int, int) = int.
curry(F) = (func(X) = (func(Y) = F(X, Y))).
uncurry(F, X, Y) = F(X)(Y).
id(F) = uncurry(curry(F)).

pplus(X, Y) = X + Y.

main -->
	{ Result = (id)(pplus)(3,4) },
	print("Result = "), print(Result), nl,
	{ Result2 = (func(X, Y) = X + Y)(5,6) },
	print("Result2 = "), print(Result2), nl.
==============================


RELATIVE DIFF
--- ri	Wed Feb 16 19:02:21 2000
+++ reference_manual.texi	Wed Feb 16 19:11:50 2000
@@ -336,15 +336,19 @@
 A parenthesized term is just an open parenthesis
 followed by a term and a close parenthesis.
 
-A higher-order term is a term, other than a name or an operator term,
-followed without
+A higher-order term is a ``closure'' term, which can be any term 
+other than a name or an operator term, followed without
 any intervening whitespace by an open parenthesis (i.e. an open_ct token),
 a sequence of argument terms separated by commas, and a close
 parenthesis.  A higher-order term is equivalent to a simple compound term
 whose functor is the empty name, and whose arguments are the 
-the variable followed by the argument terms of the higher-order term.
-That is, a term such as @code{Var(Arg1, @dots{}, ArgN)} is
-parsed as @code{''(Var, Arg1, @dots{}, ArgN)}.
+closure term followed by the argument terms of the higher-order term.
+That is, a term such as @code{Term(Arg1, @dots{}, ArgN)} is
+parsed as @code{''(Term, Arg1, @dots{}, ArgN)}.
+Note that the closure term can be a parenthesized
+term; for example, @code{(Term^FieldName)(Arg1, Arg2)}
+is a higher-order term, and so it gets parsed as
+if it were @code{''((Term^FieldName), Arg1, Arg2)}.
 
 @node Items
 @section Items

FULL DIFF
Index: reference_manual.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.172
diff -u -d -u -r1.172 reference_manual.texi
--- reference_manual.texi	2000/02/11 05:04:05	1.172
+++ reference_manual.texi	2000/02/16 08:11:50
@@ -317,27 +317,38 @@
 A functor is an integer, a float, a string, a name, a compound term,
 or a higher-order term.
 
-A compound term is a name followed without any intervening
+A compound term is a simple compound term, an operator term,
+or a parenthesized term.
+
+A simple compound term is a name followed without any intervening
 whitespace by an open parenthesis (i.e. an open_ct token),
 a sequence of argument terms separated by commas, and a close
-parenthesis.  Compound terms may also be specified using
-operator notation, as in Prolog.
+parenthesis.  
 
-Operators can also be formed by enclosing an variable or name between grave
+An operator term is a term specified using operator notation, as in Prolog.
+Operators can also be formed by enclosing a variable or name between grave
 accents (backquotes).  Any variable or name may
 be used as an operator in this way.  If @var{fun} is a variable or name,
 then a term of the form @code{@var{X} `@var{fun}` @var{Y}} is equivalent to 
 @code{@var{fun}(@var{X}, @var{Y})}.  The operator is treated as having the
 highest precedence possible and is left associative.
 
-A higher-order term is a variable followed without any intervening
-whitespace by an open parenthesis (i.e. an open_ct token),
+A parenthesized term is just an open parenthesis
+followed by a term and a close parenthesis.
+
+A higher-order term is a ``closure'' term, which can be any term 
+other than a name or an operator term, followed without
+any intervening whitespace by an open parenthesis (i.e. an open_ct token),
 a sequence of argument terms separated by commas, and a close
-parenthesis.  A higher-order term is equivalent to a compound term
+parenthesis.  A higher-order term is equivalent to a simple compound term
 whose functor is the empty name, and whose arguments are the 
-the variable followed by the arguments of the higher-order term.
-That is, a term such as @code{Var(Arg1, @dots{}, ArgN)} is
-parsed as @code{''(Var, Arg1, @dots{}, ArgN)},
+closure term followed by the argument terms of the higher-order term.
+That is, a term such as @code{Term(Arg1, @dots{}, ArgN)} is
+parsed as @code{''(Term, Arg1, @dots{}, ArgN)}.
+Note that the closure term can be a parenthesized
+term; for example, @code{(Term^FieldName)(Arg1, Arg2)}
+is a higher-order term, and so it gets parsed as
+if it were @code{''((Term^FieldName), Arg1, Arg2)}.
 
 @node Items
 @section Items
-- 
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.
--------------------------------------------------------------------------
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