[m-dev.] [reuse] fixes of some naughty bugs

Fergus Henderson fjh at cs.mu.OZ.AU
Sun Mar 11 04:55:10 AEDT 2001


On 11-Mar-2001, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> 
> This leaves one question, though:  is it fair to call a predicate pure if it
> destructively modifies a term in a way that leaves it equal to what it
> originally was, but may create new aliases?

So long as the aliasing respects the mode declaration,
I'd say yes.

> Eg, consider a predicate
> eq(pair(T)::in,pair(T)::in) that, after verifying that its arguments are
> equal, destructively replaced both arguments of the first pair with the
> corresponding arguments of the second.  This is semantically pure, but
> operationally impure.  Would I be wrong not to declare it impure?

No.

For an example of real code which does something similar to this,
see lazy__force/1 in extras/lazy_evaluation.

Why do you say it is "operationally impure"?
What do you mean by "operationally impure"?

When I say that something is pure, I mean that it has
a declarative semantics, and that its operational
semantics is sound w.r.t. that declarative semantics.

Of course if the predicate had mode

	:- mode eq(pair(T)::ui,pair(T)::ui).

and it behaved as you described, then it would be wrong.
But IMHO the right terminology for this kind of wrongness is
to say that the definition is not well-moded, not that
it is impure.

> But whether even that is ok or not is also unclear.  Suppose two ground terms
> have different types but identical representations (the same size and bit
> pattern).  I can't see why it wouldn't be correct for them to cohabitate.
> Does the Mercury language forbid it?

No, so long as they don't have unique modes.

> I can even imagine an aggressive
> Mercury compiler putting them in read-only memory and compressing that space
> by sharing as much representation as possible.  I can also imagine a term
> serializer (code to write out a term to a file in compact binary
> representation) might create such inter-type aliases.

Yes.  Also garbage collectors can introduce such sharing.

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