ocaml检查列表是否按顺序排序

ocaml检查列表是否按顺序排序,ocaml,Ocaml,我不知道该如何处理这个问题,但我需要检查列表是否按顺序排列 这就是我正在做的: let rec is_sorted_aux l res = match l with [] -> res | (h1::h2::t) -> if (h2 > h1) then is_sorted_aux t false else is_sorted_aux t true ;; 但这是比较1&&2、3&&4等中的元素对,而不是所有元素都与它们的邻

我不知道该如何处理这个问题,但我需要检查列表是否按顺序排列

这就是我正在做的:

let rec is_sorted_aux l res = match l with
    [] -> res
  | (h1::h2::t) ->
    if (h2 > h1) then
      is_sorted_aux t false
    else 
      is_sorted_aux t true
;;
但这是比较1&&2、3&&4等中的元素对,而不是所有元素都与它们的邻居进行比较

我将如何处理此问题?

使用
作为

| h1 :: (h2 :: _ as t) -> |h1::(h2::uu作为t)-> 此外,您可以在比较失败时立即返回,而不是在列表结束前携带
false


而且你不应该忽视你得到的警告。

在一个模式中,
p as x
意味着匹配模式
p
(可能包含几个部分),并且给匹配整个模式p的任何东西命名
x
。在本例中,
p
h2::
,列表的尾部。语言拼写为“OCaml”。