(下面的摘录来自这个测试套件,它是这里找到的两文件程序的一半。)
我以两种方式定义了辅助谓词:一次在顶层(称为helper
),一次作为 lambda(称为Helper
)。在下面代码的最后三行中,我使用了那个辅助谓词。如果我使用helper
它可以工作,但如果我使用Helper
我会得到一个错误(如下)。
我怀疑问题可能是我能够为类型级别谓词指定类型签名和模式签名,但只能为 lambda 指定模式签名。(如果这是问题所在,我不知道该怎么办。)
以下是相关代码:
:- pred helper( query, int ).
:- mode helper( in, out ) is nondet.
helper( Q, F ) :-
inQuery( fiveNumberSpace, Q, F ).
testQAnd = Res :-
QQF = qqFind( qFind( list.filter( <(3) ) ) )
, QQC = qqCond( qCond( func( Int )
= (if Int > 4 then no else yes) ) )
, Helper = ( pred( Q :: in, F :: out ) is nondet :-
inQuery( fiveNumberSpace, Q, F ) )
% TODO Why can't I use Helper instead of helper for these?
, solutions( helper( qqAnd( [QQF ] ) ) , F1 )
, solutions( helper( qqAnd( [QQF, QQC] ) ) , F2 )
, solutions( helper( qqAnd( [ QQC] ) ) , F3 )
这是我从使用中得到的错误Helper
:
Making Mercury/cs/test.c
test.m:098: In clause for function `testQAnd'/0:
test.m:098: in argument 1 of call to predicate `solutions'/2:
test.m:098: in unification of argument
test.m:098: and term `Helper(V_34)':
test.m:098: type error in argument(s) of higher-order term (with arity 1).
test.m:098: Functor (Helper) has type `pred(query.query, int)',
test.m:098: expected type was `((func V_13) = V_14)'.
** Error making `Mercury/cs/test.c'.