1
我想解决我的代码多个if-else循环。嵌套如果-else循环错误 - ocaml
我以前的代码为:
let rec appendtolist n list b =
let f x =
if (b == 0) then x
else (append (appendtocode n (List.hd list)) (appendtolist n (List.tl list) (b-1)))
in
f list
;;
修改后的代码与嵌套循环:
let rec appendtolist n list b =
let f x =
if b < 0 then x
else if (b == 0) then appendtocode n (List.hd list) (b-1)
else appendtocode n (List.hd list) :: appendtolist n (List.tl list) (b-1)
in
f list
;;
但我得到这个错误:
This function is applied to too many arguments, maybe you forgot a `;'
我的代码似乎是语法正确。这是在OCaml中实现嵌套循环的正确方法吗? 我接着找到了一个在线查找if-elseif循环的例子,它工作正常。
我需要最终输出x
这是在该函数中所有递归调用appendtocode
和appendtolist
后形成的列表。
我在哪里错了?
请指导。
谢谢。
嗨。谢谢。没有意识到语法错误。我将这个问题转贴到新帖子中。而不是在这里覆盖它。再次感谢。 – JJunior 2010-11-28 21:26:30