[mercury-users] Uniqueness modes etc
Dr Mark H Phillips
mark at austrics.com.au
Thu Jan 8 12:38:08 AEDT 2004
On Wed, 2004-01-07 at 00:15, Fergus Henderson wrote:
> The Clean notation has the drawback that the variable name has to be
> mentioned twice for each function call, once on the left hand side
> of the equals and once on the right, whereas with Mercury's state
> variable notation you only need to mention the variable name once
> (prefixed with a "!").
True.
> > My thought was that maybe Mercury was similar, but with a rule
> > which said something like: di variables have scopes which end on
> > input; uo variables have scopes which start on output; and within
> > the pred expression the scopes of di and uo variables are separated.
> > In this way scoping would distinguish variables of the same name.
>
> No. In Mercury, the logical meaning of a program, i.e. its declarative
> semantics, is not affected by the modes at all. The modes only affect
> the operational semantics. So they cannot affect variable scoping.
Okay, this seems to be the killer of my scoping idea. In any case,
the drawback of my scoping idea is that it is really trying to hide
the fact that different variables are being used to represent states
in a single thread of state transitions. At least state variable
notation makes explicit that some hiding of details is going on. It
seems like monads do this also, with perhaps greater flexibility as
to precisely what details are hidden.
> > Now it seems that Mercury uses state variable notation or DCG
> > instead. Am I right though in thinking that Mercury
> > could have used a scoping approach instead?
>
> Yes.
>
> > Was the decision to go with state variable notation rather than a scoping
> > approach, one that could have gone either way, or does the
> > former have significant benefits over the latter?
>
> Clean's let-before notation only works with functions. That's OK for Clean,
> but it wouldn't work so well for Mercury, which also has predicates.
> In Mercury, procedures that have multiple outputs tend to be written
> as predicates, not as functions that return tuples.
> Mercury's state variable notation works OK with functions, e.g.
>
> writeABC(!.File) = !:File :-
> !:File = fwritec('a', !.File),
> !:File = fwritec('b', !.File),
> !:File = fwritec('c', !.File).
>
> but it works even better with predicates, e.g.
>
> writeABC(!File) :-
> fwritec('a', !File),
> fwritec('b', !File),
> fwritec('c', !File).
Okay. Thanks for the illustration and helpful comments.
Cheers,
Mark.
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list