在Warren's Abstract Machine: A Tutorial Reconstruction
中练习2.2询问术语f(X,g(X,a))和f(b,Y)的表示,然后对这些术语的地址进行统一(分别表示为a1和a2)。
我为这些术语构建了堆表示,它们如下:
f(X, g(X, a)):
0 STR 1
1 a/0
2 STR 3
3 g/2
4 REF 4
5 STR 1
6 STR 7
7 f/2
8 REF 4
9 STR 3
f(b, Y):
10 STR 11
11 b/0
12 STR 7
13 STR 11
14 REF 14
我现在被要求跟踪统一(a1,a2),但按照1中第20页的算法得到:
d1 = deref(a1) = deref(10) = 10
d2 = deref(a2) = deref(0) = 0
0 != 10 so we continue
<t1, v1> = STORE(d1) = STORE(10) = <STR, 11>
<t2, v2> = STORE(d2) = STORE(0) = <STR, 1>
t1 != REF and t2 != REF so we continue
f1 / n1 = STORE(v1) = STORE(11) = b / 0
f2 / n2 = STORE(v2) = STORE(1) = a / 0
and now b != a so the algorithm terminated with fail = true,
and thus unification failed, but obviously there exists
a solution with X = b and Y = g(b, a).
我的错误在哪里?
答案 0 :(得分:1)
我自己找到了解决方案。这是我的更正:
每个术语都应该有自己的仿函数定义(即第二项中的f-functor不应该仅仅链接到第一个术语中的第一个f-functor,而应该有自己的f-functor)和指向这些术语的指针(a1和a2)应指向最外面的术语仿函数。
这意味着在以下布局中a1 = 6和a2 = 12
f(X, g(X, a)):
0 STR 1
1 a/0
2 STR 3
3 g/2
4 REF 4
5 STR 1
6 STR 7
7 f/2
8 REF 4
9 STR 3
f(b, Y):
10 STR 11
11 b/0
12 STR 13
13 f/2
14 REF 11
15 REF 15