2

我知道一点 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 中进行约束求解?

4

1 回答 1

0

那篇论文并没有说你现在可以像在 Prolog 中那样在 Mercury 中进行约束求解。它描述了当时添加到 Mercury 的功能,以支持在 Mercury 中编写约束求解器,然后 使用生成的求解器,这是完全不同的。

Mercury 没有也不会有任何内置的约束求解器。

于 2020-02-29T08:34:07.280 回答