Consider the following code in F#
let rec ordered xs =
match xs with
| [] | [_] -> true
| x1 :: x2 :: xs' -> x1 <= x2 && ordered (x2 :: xs')
and then
let rec insert x xs =
match xs with
| [] -> [x]
| y :: ys -> if x <= y then x :: y :: ys
else y :: insert x ys
and finally
let insertKeepsOrder (x : int) xs = ordered xs ==> ordered (insert x xs)
What i can not understand is the ==>
meanning in the last line!!!
What is it?
The ==>
operator is part of FsCheck . It is used to express a property that should hold only if some condition is true .
So in your example:
let insertKeepsOrder (x : int) xs = ordered xs ==> ordered (insert x xs)
This means ordered (insert x xs)
should be true only if ordered xs
is true.
You can read more about this in the "Conditional Properties" section of the FsCheck documentation .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.