这是我对这个问题的想法,但我无法正确输入fold_left
方法。
例子:
nonDecreasing[1;4;3;2;5;6] == [[1;4];[3];[2;5;6]]
let nonDecreasing list =
match list with
| [] -> help(a, b, c) = b
| h::[] -> 2 (*I don't know, "2" is only to compile*)
| h::t -> let help = List.fold_left (fun(prev, lFinal, lTemp) h -> if(h<List.hd(t)) then (List.hd(t), lFinal, h::lTemp) else (List.hd(t), lTemp@lFinal, h::lTemp)) (h, [], []) list ;;
I can't make it properly. I don't know what I do wrong with fold-left function.