我正在尝试编写此函数gencut(n,xs),该函数会将列表xs分成2个,其中n作为第一个列表的元素数。它是这样的:
let rec gencut(x, ys) =
let rec gencutaux (x, xs, ys) = // Here's my problem!
match (x, ys) with
| (0, []) -> (List.rev xs, ys)
| (x, []) -> (List.rev xs, ys)
| (0, ys) -> (List.rev xs, ys)
| (x, y :: ys) -> gencutaux (x - 1, y :: xs, ys)
gencut(4, [1;2;3;4;5]);;
但是,我在第二行中有一个错误。每当我尝试运行它时,控制台都会说:“此'let'之后的阻止未完成。请期待一个表达式。” 我不知道为什么会这样,或者我必须怎么做才能更正它。任何见解均表示赞赏。
您可能必须致电gencutaux
:
let rec gencut (x, ys) =
let rec gencutaux (x, xs, ys) =
match (x, ys) with
| (0, []) -> (List.rev xs, ys)
| (x, []) -> (List.rev xs, ys)
| (0, ys) -> (List.rev xs, ys)
| (x, y :: ys) -> gencutaux (x - 1, y :: xs, ys)
gencutaux (x, xs, [])
您不能以变量定义结尾块,因为这没有任何意义。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句