[m-dev.] Reopened: state vars syntax sugar

Jonathan Morgan jonmmorgan at gmail.com
Mon Jan 29 23:32:58 AEDT 2007


On 1/29/07, Peter Schachte <schachte at csse.unimelb.edu.au> wrote:
> One solution to the problem Ondrej pointed out with ::! being a single token
> would be for ! to only appear at the top level of an argument position in a
> pred, mode, or predmode declaration.  Then ! in front of an argument position
> means "this argument is a state variable."  So in a predmode declaration, the !
> semantically extends over both type and mode.  Eg, if a call to foo looks like:
>
>         ..., foo(Something, !Counter, !IO), ...
>
> then the pred and mode declarations might look like:
>
>         :- pred foo(something, !int, !io).
>         :- mode foo(in, !ground, !destructive).
>
> which would be the same as:
>
>         :- pred foo(something::in, !int::ground, !io::destructive).

This one doesn't look right without the brackets.  At a minimum I
would want !int::!ground or !(int::ground), otherwise it doesn't
particularly show that the ground is two arguments (this is not a
problem with !int::(in, out)).  When you add the fact that ground can
also be part of an instance this can only lead to confusion.

> Or, if the relative precedence of ! and :: isn't right, it would have to be
>
>         :- pred foo(something::in, !(int::ground), !(io::destructive)).
>
> which still looks pretty good to me.
>
> So Julien and other non-Peters in this discussion:  what's your objection to
> this approach?

I think that !int::(in, out) is a preferable syntax because it allows
the state variable notation for the type, but it is still readily
apparent that the mode refers to an in/out pair.  Your suggestion
requires a different mode syntax to be learned to use state variable
modes, which I don't think is desirable.  It is also fairly close to
the minimal change, allowing changes to support state-var like modes
later once the argument has been played out.

Just out of interest, would both of the following be allowed under your scheme?

:- pred main(!io).
:- mode main(di, uo) is det.

:- pred main(io, io).
:- mode main(!destructive) is det.

Jon
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions:          mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the developers mailing list