Sorting 排序列表在F中从高到低#

Sorting 排序列表在F中从高到低#,sorting,f#,Sorting,F#,将列表从低到高排序-如何从高到低排序?这有什么库函数吗 有关数字列表: List.Sort 函数(fun x->-x)对数字求反,从而颠倒顺序 对于一般的比较,使用List.sortWith和compare。遵守compare中ab的顺序: list |> List.sortBy (fun x -> -x) 如果查看链接的线程,使用List.sortBy(fun x->-x)时可能会出现溢出。正确的说法应该是: > List.sortWith (fun a b ->

将列表从低到高排序-如何从高到低排序?这有什么库函数吗

有关数字列表:

List.Sort
函数
(fun x->-x)
对数字求反,从而颠倒顺序

对于一般的比较,使用
List.sortWith
compare
。遵守
compare
ab
的顺序:

list
|> List.sortBy (fun x -> -x)

如果查看链接的线程,使用
List.sortBy(fun x->-x)
时可能会出现溢出。正确的说法应该是:

> List.sortWith (fun a b -> compare a b) ["a";"s";"d";"f"];;
val it : string list = ["a"; "d"; "f"; "s"]
> List.sortWith (fun a b -> compare b a) ["a";"s";"d";"f"];;
val it : string list = ["s"; "f"; "d"; "a"]
在F#4.0(Visual Studio 2015预览版附带)中,有
sortdescing/sortbydescing
函数可用于此目的

你可以用

List.sortBy (fun x -> -x-1)


请参阅。

上的新核心库函数的综合列表。您可以使用
list.sortBy
按自定义函数排序,并使用一元减号运算符
~-
作为紧凑表示法中的函数:

list
|> List.sortByDescending id
可能重复的
list
|> List.sortByDescending id
let list = [1..10]
list |> List.sortBy (~-)