[mercury-users] impure predicates

Henk Vandecasteele Henk.Vandecasteele at cs.kuleuven.ac.be
Wed Oct 21 01:06:08 AEST 1998


Ralph Becket wrote:
> 
> Henk Vandecasteele wrote on 20 Oct:
> >
> > So, should the mercury-system backtrack over impure
> > predicates which have only input-arguments?
> 
> I'd say no.  Typically, a predicate with no output args is going to be
> semidet or erroneous (anything else doesn't make much sense to me).
> Backtracking over impure operations also sounds rather dodgy to me -
> what are you trying to do?

I'm still porting a finite domain solver to mercury. I have already a 
version using an input and output representing the state of the world.

For effiency reasons I use backtrackable destructive assignment 
for updating the information about finite domain-variables.
The extra argument is then a mostly unique array with trailed
backtrackable destructive update. The finite domain variables
are numbers referring to the array.

When implementing this stuff it is far more easy to store the
information IN the finite domain variable. Then the number, previous
refering to the global state-array, is replaced 
by a structure which can be updated with backtrackable destructive
assignment.

As a result some predicates have no output arguments, ... .

This technique is also used in the prolog-implementation based 
on backtrackable destructive assignment in SICStus.

Of course I agree that the finite domain language should have the
the in/out state-variables, becoming declarative again.
This is not really a penalty, in a usual finite domain program, almost
all the execution time is spent inside the solver.
Maybe the mercury-compiler could afterwards optimise them away?

Regards,

Henk





More information about the users mailing list