When sorting tuples, you can use the fact that F# sorts tuples lexicographically. This means that the first element is ordered in ascending order and in case of a tie, it sorts at the second element in increasing order.

What you want to do is slightly different: you want to sort the first element descending (non-standard ordering) and the second ascending (standard ordering). Now here's a trick: sorting values x in descending order is the same as sorting -x in ascending order.

To perform this trick, you can use sortBy, which sorts using a transformed version of the data as keys:

1
let sortedTuple = aTuple |> Array.sortBy (fun (x,y) -> (-x,y))

Note that this doesn't transform the data itself, it just sorts on the transformed version of the input data.

By on 1/10/2010 6:09 AM ()

Hello, Cfern:
Thank you very much, your code works.
Also, thank you again for the good explanation.
Have a nice day!

By on 1/10/2010 7:23 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper