我想創建包含在OCaml的列表字符串的排列。 到目前爲止,我一直在處理以下代碼片段,但面臨着將列表的第一個字符串傳遞給我的方法的問題。錯誤 - 通過傳遞列表遞歸函數調用 - OCaml的
邏輯的代碼: 迭代到列表中的每個元素,並且每個元素與所述列表的元素追加。繼續執行,直到所有元素都被添加到列表中的每個可能位置。
代碼:
(* this function appends each string to each word in the list example: "A" with "ABC" *)
let appendtocode n word =
let f x = n^x in
f word
;;
(* this function extracts every element of the list and appends it with the string.
Example: "A" with ["AAA","ABC","ACD"] etc.. *)
let appendtolist n list =
let f x =
if (List.length list) > 0 then list
else ((appendtocode n (List.hd list))^(appendtolist n (List.tl list)))
in
List.map f list
;;
錯誤:
我得到這個錯誤:
沒有限制值appendtolist
發生在調用:(appendtolistñList.tl名單)
我的列表只是由字符串組成。 我仍在處理代碼。但由於這個錯誤而停留在此處。
請幫忙!!!任何輸入都會很棒。
這是爲什麼標籤SML和smlnj如果你使用ocaml的? – sepp2k 2010-11-27 23:40:04
我修復了標籤,因爲這絕對是OCaml,與SML沒有明顯的聯繫。 – Porculus 2010-11-27 23:42:14