[mercury-users] Constraints and conditionals in Mercury

Mark Brown mark at csse.unimelb.edu.au
Mon Apr 14 12:22:53 AEST 2008

On 13-Apr-2008, Peter Schachte <schachte at csse.unimelb.edu.au> wrote:
> Ralph Becket wrote:
> > Richard A. O'Keefe, Friday, 11 April 2008:
> >> knights_tour/1 has one argument, an integer.  It is known to be ground.
> >> There is a conditional
> >>
> >> 	if knights_tour(N) then ... else ...
> >>
> >> The implementation of knights_tour/1 uses constraints *internally* to
> >> determine whether there exists at least one knight's tour on an NxN
> >> board or not.  Suppose that knights_tour(N) leaves some constraints
> >> pending when it exits, and that for some value of N those constraints
> >> are not satisfiable.
> > 
> > Right now: we don't catch this situation.  We have discussed the
> > problem, however.  One suggestion was to look out for cases where
> > a solver variable goes out of scope without having become ground
> > and require some kind of promise of good behaviour from the programmer.
> The problem with that is that the promise could be a lie, and there may be no
> way for the caller to make it true.  I suggested there should be a way for
> Mercury to force a constraint solver to either satisfy all pending
> constraints if it ca, fail if it can determine they're unsatisfiable, or
> throw an exception if it can't do either.  The Mercury compiler would then
> force a decision in negated contexts and anywhere else it has to commit.

For commits, there is the ability to do this using the function trailing
interface.  The callback, when called, is passed a "reason" for the trail
being unwound.  The functions can be called not just on failure, but also
on exceptions, commits, etc.  These functions could be made to check for

(Sorry, due to network problems I can't look up the URL for this.)


mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au

More information about the users mailing list