[英]Mercury List Unification
I'm trying to learn Mercury .我正在努力学习Mercury 。 I've been messing around with lists, but I can't get a seemingly-simple unification to work.
我一直在处理列表,但我无法获得看似简单的统一工作。 Here's my reduced example case:
这是我简化的示例案例:
main(!IO) :-
[X,Y] = List,
List = [1,2], % Error
io.write(List, !IO),
io.nl(!IO).
On the line List = [1,2]
I get the following error (formatted and slightly edited):在
List = [1,2]
我收到以下错误(已格式化并稍作编辑):
main.m:024: In clause for `main(di, uo)':
mode error in unification of `List' and `list.[V_11 | V_21]'.
Variable `List' has instantiatedness
`unique(list.'[|]'(free, unique(list.'[|]'(free, unique((list.[]))))))',
term `list.[V_11 | V_21]' has instantiatedness
`list.'[|]'( unique(1), free )'.
That doesn't seem right, though;不过,这似乎不对; specifically the instantiatedness of
[1,2]
.特别是
[1,2]
的实例化。 It's a literal;这是一个字面意思; shouldn't its instantiatedness be, like,
list.'[|]'( unique(1), list.'[|]'( unique(2), [] ) )
?它的实例化不应该像
list.'[|]'( unique(1), list.'[|]'( unique(2), [] ) )
吗?
Is this related somehow to the same partial-instantiation problem as here ?这是否与此处相同的部分实例化问题有关?
To compile a mode-correct program Mercury will re-order goals within a conjunction to try to make a mode-correct program, but before it does this it'll also break complex unfications up into parts.为了编译一个模式正确的程序,Mercury 将重新排列合中的目标以尝试制作一个模式正确的程序,但在此之前,它也会将复杂的 unfications 分解成多个部分。 It looks like Mercury is struggling to re-order the parts of these two unifications to make a mode correct program, even though (from my looking) it should be possible.
看起来 Mercury 正在努力重新排序这两个统一的部分以制作模式正确的程序,尽管(从我看来)这应该是可能的。 Try re-ordering the first two goals.
尝试重新排序前两个目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.