clpmercury

Mercury Constraint Solving


I know a little Prolog, and frequently use CLP(FD) etc. This paper (written in 2006, apparently) indicates that Mercury now has constraint solving, too. I've found a few mentions of it in the Library Reference Manual. However, I can't find how to use it. For instance:

main(!IO) :-
   A >= 2,
   A =< 2,
   io.write(A, !IO).

gives compiler error

test1.m:011: In clause for `main(di, uo)':
test1.m:011:   in argument 1 of call to predicate `int.>='/2:
test1.m:011:   mode error: variable `A' has instantiatedness `free',
test1.m:011:   expected instantiatedness was `ground'.

but in Prolog, with clpfd,

A #>= 2, A #=< 2.

works fine, giving A = 2 .

(Adding #s to the Mercury code doesn't help.)

How do you do constraint solving in Mercury?


Solution

  • That paper does NOT say the you can now do constraint solving in Mercury the same way as you can do in Prolog. It describes features added to Mercury at the time to support writing constraint solvers in Mercury, and then using the resulting solvers, which is quite different.

    Mercury does not have, and will not have, any builtin constraint solvers.