我知道一点 Prolog,并且经常使用 CLP(FD) 等。 这篇论文(显然写于 2006 年)表明 Mercury 现在也有约束求解。我在图书馆参考手册中发现了一些提及它。 但是,我找不到如何使用它。例如:
main(!IO) :-
A >= 2,
A =< 2,
io.write(A, !IO).
给出编译器错误
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'.
但在 Prolog 中,使用 clpfd,
A #>= 2, A #=< 2.
工作正常,给 A = 2 。
(在 Mercury 代码中添加 #s 无济于事。)
您如何在 Mercury 中进行约束求解?