[m-dev.] Resources example

Ralph Becket rafe at cs.mu.OZ.AU
Fri Apr 22 18:25:24 AEST 2005

Peter Schachte, Friday, 22 April 2005:
> eq(A, B) :-
> 	promise_pure (impure X = 'representation of any po_vertex/0'(A),
> 		      impure Y = 'representation of any po_vertex/0'(B)),
> 	( if   path(X, Y, [], nonstrict)
> 	  then path(Y, X, [], nonstrict)
> 	  else not path(X, Y, [], strict),
> 	       svset.insert(le(Y,X), !po_store),
> 	       svset.insert(le(X,Y), !po_store)
>         ).

Talking to Julien, we observe that this promise_pure goal, like others
in this example, is poorly scoped.  It is only the clause as a whole
that can be considered to have a pure interface.  The 'representation of
...' functions are impure because a non-ground solver value may have a
ground representation, which can only make sense in the context of the
constraint store.  But that's implicit, hence the impurity annotation!

A good fix would be to make 'representation of ...' use the !po_store
resource, in which case they would be pure.

I'm going to put my hand up here and say that my main concern about
resources is the huge scope for abuse.  But I also acknowledge that
sometimes imperative style is the clearest way to express things and
there is a good case for providing support for disciplined imperative

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