【发布时间】:2017-01-27 21:22:19
【问题描述】:
我正在尝试使用下面给定的模板在不使用 List.Max 的情况下查找列表中的最大元素。
let findMax l =
let rec helper(l,m) = failwith "Not implemented"
match l with
| [] -> failwith "Error -- empty list"
| (x::xs) -> helper(xs,x)
我能想到的唯一解决方法,atm就是
let rec max_value1 l =
match l with
|[] -> failwith "Empty List"
|[x] -> x
|(x::y::xs) -> if x<y then max_value1 (y::xs)
else max_value1 (x::xs)
max_value1 [1; 17; 3; 6; 1; 8; 3; 11; 6; 5; 9];;
有什么方法可以从我构建的功能转到使用模板的功能?谢谢!
【问题讨论】: