我们可以将高阶映射谓词定义为:
map([], [], F).
map([A|As], [B|Bs], F) :-
call(F, A, B),
map(As, Bs, F).
同样,我们可以将折叠(左)定义为:
fold([], Acc, Acc, _F).
fold([A|As], B, Acc1, F) :-
call(F, Acc1, A, Acc2),
fold(As, B, Acc2, F).
reduce(左)的正确定义是什么?我们可以这样定义吗?
reduce([A|As], Bs, F) :-
fold(As, Bs, A, F).
和reduceback(右)如下?
reduceback([], Ident, F) :-
identity(F, Ident).
reduceback([A|As], B, F) :-
reduceback(As, C, F),
call(F, C, A, B).
这些是正确的吗?