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