2

考虑 F# 中的以下代码

let rec ordered xs = 
    match xs with
      | [] | [_]        -> true
      | x1 :: x2 :: xs'  -> x1 <= x2 && ordered (x2 :: xs')

接着

let rec insert x xs = 
    match xs with
    | []      -> [x]
    | y :: ys -> if x <= y then x :: y :: ys 
                 else           y :: insert x ys

最后

let insertKeepsOrder (x : int) xs = ordered xs ==> ordered (insert x xs)

我无法理解的是==>最后一行的含义!

它是什么?

4

1 回答 1

6

==>操作员是FsCheck的一部分。它用于表示仅在某些条件为真时才应保持的属性。

所以在你的例子中:

let insertKeepsOrder (x : int) xs = ordered xs ==> ordered (insert x xs)

这意味着只有在为ordered (insert x xs)真时才ordered xs为真。

您可以在 FsCheck 文档的“条件属性”部分阅读更多相关信息。

于 2015-11-17T20:20:44.207 回答