我可以通过以下代码找到列表的最后一个元素。
let last (xs:'a list) : 'a =
let rec aux xs prev =
match xs with
| [] -> prev
| x::ys -> aux ys x in
match xs with
| [] -> failwith "no element"
| x::xs -> aux xs x
如何使用List.fold_left
OCaml 中的函数找到同一列表的最后一个元素?提前致谢!