我想创建包含在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