[mercury-users] higher order syntax
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Feb 11 15:12:36 AEDT 2000
On 10-Feb-2000, Ralph Becket <rbeck at microsoft.com> wrote:
> The mercury syntax allows us to write `P(...)' and
> `F(...)' in place of `call(P, ...)' and `apply(F, ...)'
> respectively, provided P/F are *variables*
> bound to predicate/function values.
>
> On the other hand, if I have, say
>
> :- func f = (func(T1) = T2).
>
> as crops up in, for instance, the monadic style,
> I have to write `apply(f, X)' rather than just
> `f(X)'.
I don't understand why you would ever
write `:- func f = (func(T1) = T2).'.
Why not just write `:- func f(T1) = T2.'?
> Similarly, if F has type `func(T1) = (func(T2) = T3)'
> then I have to write `apply(F(X), Y)'.
That example makes more sense.
> Would it be
> hard to extend the convenience syntax so that one
> could write `F(X)(Y)' instead? Or, if it makes life
> any easier for the parser writers, `(F(X))(Y)' and
> `(f)(X)'? This syntax looks clearer and less mixed up
> and, IIRC, it's what the XSB/HiLog people do.
Probably not.
The main difficulty with that would be with binary prefix
operators. If `op' is a binary prefix operator, how should
op (X)(Y)
be parsed? Currently it gets parsed as 'op'(X, Y).
With your proposal, I guess the (X)(Y) would be parsed
as ''(X, Y), and so the example above would be a syntax error,
since it uses a binary prefix operator with only one operand.
Still, that's not a big problem. Arguably this behaviour would
in fact be more consistent, since currently
op(X) (Y)
is a syntax error.
Currently the only binary prefix operators in Mercury syntax
are `some', `all', and the obsolete `lambda'. So that issue is
not a big deal, I guess. There is a backwards compatibility issue
with code like `some[X](...)', though, which would need to
be changed to e.g. `some [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.
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list