【发布时间】:2018-09-11 11:20:45
【问题描述】:
这就是我想要实现的,通过 recursion 返回一个值低于给定值的列表:
# list_below 3 [7; 1; 0; 3];;
- : int list = [1; 0]
# list_below 1 [-7; 1; 0; 3];;
- : int list = [-7; 0]
# list_below 9.0 [4.2; 3.6; 5.0; 12.8];;
- : float list = [4.2; 3.6; 5.0]
这是我到目前为止所写的,它似乎没有返回任何内容。
let rec list_below thresh lst =
if List.hd lst > thresh then [] else
List.hd lst :: list_below thresh (List.tl lst);;
;;
你能告诉我我的代码有什么问题吗?
【问题讨论】: