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

Peter Schachte schachte at csse.unimelb.edu.au
Mon Jan 29 15:13:12 AEDT 2007


Julien Fischer wrote:

> So far the only people in favour of the !<inst> syntax all seem
> to be named Peter.

Yeah, but there's no shortage of people named Peter around the project ;-)

> I'm not convinced it's a particularly good idea.

What I was trying to do was create a syntax that made it impossible to express
a mode pair that isn't sensible for a state thread.  Everyone seems to be happy
specifying the type of a state var only once; obviously the input and output
types for a thread must be the same.  But it's also the case that the final
inst of the output must match the initial inst for the input; a goal must leave
the state var in the same inst as it found it.  So it would be preferable *not*
to have a syntax that would allow you to say (in,in) or (out,out) or any number
of other nonsensical mode pairs.

The other goal was to make the syntax look consistent.  I think type::(in,out)
is pretty unappealing, for the same reason I don't like specifying two
arguments in the pred declaration where only one appears in the goal:  it's
just inconsistent and confusing.  Where the goal shows a single argument, I'd
rather the pred declaration show a singe type specification and the mode
declaration show a single mode specification.  If type::(mode, mode) is
allowed, why shouldn't we allow type::(mode, mode, mode), as well?  Eg,
append(list(T)::(in, in, out)).  And for that matter, shouldn't we also allow
append((list(T), list(T))::in, list(T)::out)?

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

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?

-- 
Peter Schachte              When I give food to the poor, they call me a
schachte at cs.mu.OZ.AU        saint. When I ask why the poor have no food,
www.cs.mu.oz.au/~schachte/  they call me a communist.
Phone: +61 3 8344 1338          -- Dom Helder Camara
--------------------------------------------------------------------------
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