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