我试图在未使用List.Max的情况下在使用下面给定的模板的学校作业中找到列表中的最大元素。使用模式匹配和递归在列表中查找最大元素F#
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];;
有什么办法,我可以从我建一个使用模板功能去?谢谢!
可能的重复[我如何从列表中获取最大值与函数,需要两个参数?](http://stackoverflow.com/questions/13474382/how-do-i-get-the-max - 值 - 从 - 一个列表上带有一个功能 - 即通吃两个参数) –