[m-dev.] for review: improvements for record syntax
Fergus Henderson
fjh at cs.mu.OZ.AU
Thu Dec 7 02:22:42 AEDT 2000
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).
> > > >
> > > > 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.
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)'.
> > 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?
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?
> 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.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- 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