[m-dev.] Fw: Re: Impurity annotations on clauses

Peter Schachte schachte at csse.unimelb.edu.au
Fri Jan 19 13:19:27 AEDT 2007


Maria Garcia de la Banda <Maria.GarciadelaBanda at infotech.monash.edu.au> wrote:
> Ralph Becket wrote:
>> I'm just debugging a change to the compiler to support putting impurity
>> annotations on clause heads as an alternative to placing them on all
>> impure goals in the clause bodies.  There's some resistance to the idea
>> at the Melbourne end (i.e. we're going to have a syntax fight over
>> this...) and it would be helpful if you could send me any copies of your
>> Mercury modules that are currently festooned with impurity annotations
>> so I can use them as ammo in the forthcoming debate.
> 
> which I find extremely relevant. Considering how many people are nowdays
> implementing impure things, it might be easier to convince them now (I bet most
> of the solvers code is festoned with impure keywords). What do you think?

If we're going to dredge up old battles, I'll weigh in....

I agree with Maria that having code festooned with impurity declarations is
undesirable.  They're a nuisance to write and they obscure the logic of the
code.  But more importantly, they are too blunt an instrument:  they say 'all
bets are off in this chunk of code'.  Putting a single impurity declaration at
the front of the clause fixes the two smaller problems, but makes the bigger
one worse, since then there's nothing in the clause whose semantics is simple.
 If all bets really are off everywhere in the clause, having a single impurity
declaration at the front is probably an improvement.  But I think in most cases
it would be far preferable to have a more fine-grained kind of impurity that
admits, in a syntactically lightweight way, that a particular goal is impure,
but only with respect to certain resources.

Everyone is pretty happy using state variables.  They provide an easily
understood kind of impurity, as the same name denotes different values in a
single execution of a single clause.  Thus the order of goals in the clause is
significant, but only in so far as those state variables are concerned.  My
resources proposal gives exactly that facility, but where the state variables
are only mentioned in the pred declarations of the involved predicates, not in
each call.  Calls to predicates that use resources have a single ! character in
front indicating that the goal is impure, but only with respect to the
resources listed in that predicate's pred declaration.  Thus the semantics are
precisely documented and checked by the compiler (unlike "promise pure"), the
order sensitivity of goals is documented in place with little visual noise in
the source code, and yet values private to certain modules of the computation
need not be threaded throughout the code.

-- 
Peter Schachte              Nobody goes there anymore; it's too crowded.
schachte at cs.mu.OZ.AU            -- Yogi Berra
www.cs.mu.oz.au/~schachte/
Phone: +61 3 8344 1338
--------------------------------------------------------------------------
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