【发布时间】:2013-10-27 21:48:28
【问题描述】:
看看我的代码:
let my lst p q =
if lst = [] then
[]
else
let i = 0 in let res = [] in let acc=[] in
fold_left ( fun acc h ->
if (not (p h) && not(q h)) then
((i+1), [], res)
else if (p h && not (q h)) then
((i+1), (i::acc),res)
else if (not (p h) && q h) then
((i+1), [] (acc@res))
else
((i+1), [], ((i::acc)@res)))
(i,acc,res) lst;;
我得到了编译错误:
这个表达式的类型为 int * int list * 'a list 但是需要一个 int list 类型的表达式
你能帮帮我吗?
【问题讨论】:
-
编译错误是指哪一行?
-
((i+1), (i::acc),res)
-
我猜这里有一个错字
(i+1), [] (acc@res))缺少逗号
标签: ocaml fold type-mismatch