By default List.sort
sorts in ascending order, with the compare
function.
There are two ways to sort in descending order: one efficient and one inefficient.
List.sortWith
and a descending comparison function.descending a b =
case compare a b of
LT -> GT
EQ -> EQ
GT -> LT
> List.sortWith descending [1,5,9,7,3]
[9,7,5,3,1] : List number
List.sort
and then List.reverse
.> List.reverse (List.sort [1,5,9,7,3])
[9,7,5,3,1] : List number