[m-dev.] for review: improvements for record syntax

Simon Taylor stayl at cs.mu.OZ.AU
Thu Dec 7 12:27:08 AEDT 2000


Fergus wrote:
> On 07-Dec-2000, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> > Fergus wrote:
> > > On 06-Dec-2000, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> > > > Fergus wrote:
> > > > > On 05-Dec-2000, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> > > > > > I see two sensible ways to handle `^'.  
> > > > > > Given the term W ^ f(X, Y), it could translate
> > > > > > into either (1) f(W, X, Y) or (2) f(X, Y, W).

> > > With (1) there is an equivalence between field selection
> > > and function application: `X ^ f(...) === f(X, ...)'.
> > > Again the only difference between `^' and `apply' is
> > > the argument ordering.
> > 
> > That's not quite right. `apply' doesn't need to know anything about
> > the name or curried arguments of the function being applied. 
> 
> Well, `^' need not know anything about the name of the function
> being applied either.  For example we could define `X ^ Y(A, B, ...)'
> to be equivalent to `Y(X, A, B, ...)'.  Nor does it need to know
> about the curried arguments -- this is just a syntactic transformation.
> So `Y = f(A), X ^ Y' means `Y = f(A), Y(X)', i.e. `f(A)(X)' or `f(A, X)',
> not `f(X, A)'.

Do you really want the transformation to give different results
depending on whether the function term is written inline in
the `^/2' term? That's horrible.
 
> > > I don't think the slightly simpler equivalence that you get with (2)
> > > is worth the unnatural argument ordering that is needed with (2).
> > 
> > What I want to do is remove the restrictions on the field argument
> > to ^/2 terms to provide a syntax for chained function application
> > that is sometimes more readable. Instead of `H(2, g(1, F(X)))'
> > you could write `X ^ F ^ g(1) ^ H(2)'.
> 
> Can you give a realistic example of when this would be useful?

It's just chained function application. It's pretty common.
 
> What if you want a more readable syntax for `H(g(F(X), 1), 2)'?
> (That is what `X ^ F ^ g(1) ^ H(2)' would be equivalent to under
> proposal (1).)
> Do you think that `H(2, g(1, F(X)))' would be more common?
> If so, why?

I don't think either will be more common.
 
> > To avoid taking the address of automatically generated field access
> > functions, the transformation for ^/2 terms still needs to check
> > for cases where the top-level functor of the function term is known.
> 
> Could you elaborate?  I don't understand.

With the current implementation you can't take the address of a
function which does not have a single mode declaration.
For a function `f/1' which does not have a single user-declared
mode, `apply(f, X)' will give an error, `f(X)' won't. The
transformation of `^/2' needs to produce function calls rather
than applications of higher-order function terms where possible
to avoid these errors.

Simon.
--------------------------------------------------------------------------
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