0
我试图使这个递归函数它接受一个int x
和一个列表,然后去除第一x
量从列表中要素的:CAML/ocaml的:图案匹配多个参数的函数
let rec nthcdr int_t list_t =
match int_t with
| 0 -> list_t
| _ -> (match list_t with
| [] -> []
| h::tail -> nthcdr (int_t -1) tail)
;;
但它不起作用,h::tail
似乎永远不会匹配,它总是返回[]
无法重现。你如何测试它? – melpomene
我同意@melpomene。你为我编写代码,所以也许这是你的测试有缺陷。这是我的测试:'nthcdr 3 [1; 2; 3; 4; 5]'==>'int list = [4; 5]'。 –
我的坏家伙!我错误地测试了。 – Jose