【发布时间】:2018-09-06 22:55:57
【问题描述】:
在 F# 中使用递归,我应该编写一个递归函数来从列表 l 中删除一个整数 n。 该函数接受 int 和 iList 并返回一个 iList(即整数列表)
这是我目前所拥有的:
let rec remove n l
match l with
| E -> failwith "Empty List"
| L(h,E) -> if (h=n) then 0 else h
| L(h,t) -> if (h=n) then remove n t else h + remove n t
在上面的代码中,我对其进行了设置,以便在从列表中排除给定整数 n 后,它返回列表中元素的总和,而不是列表中的实际元素。
在排除给定整数 n 后,我需要帮助返回列表的剩余元素。
【问题讨论】:
标签: recursion f# pattern-matching