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

Simon Taylor stayl at cs.mu.OZ.AU
Thu Dec 7 01:29:14 AEDT 2000


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).
> > >
> > > Simon chose (2).
> > > I'm with Ralph in preferring (1).
> > 
> > I think it's worth keeping the equivalence between field selection
> > and function application.  The only reason they're not completely
> > equivalent now is that the compiler doesn't do mode inference for
> > higher-order terms.
> 
> Do you mean the equivalence `X ^ Y === Y(X)'?
> Or in other words '^'(X, Y) === apply(Y, X)?
> Note that `^' is not the same as `apply' because the arguments
> are in a different order.
> 
> 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. 
 
> 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)'.

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.

The new transformation would be as follows.

transform(Term ^ Func ^ Rest) = 
                transform(transform_func_application(Term ^ Func) ^ Rest).
transform(Term ^ Func) = transform_func_application(Term ^ Func).

transform_func_application(Term ^ Func(Arg1, ...)) = Func(Arg1, ..., Term).
transform_func_application(Term ^ FuncTerm) = apply(FuncTerm, Term).

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