Hi,

The confusion comes from a recent change in F# library. Your first example used to work for a long time, but it has changed (to me, it's now cleaner and easier to use).

Yesterday, I wrote a set of examples for list functions, you can have a look here: [link:man.f-sharp.fr]. For details, you can find documentation here:

[link:research.microsoft.com]

Laurent.

By on 6/25/2009 5:34 AM ()

these examples may help you

List.sort uses generic comparison. See compare in Microsoft.FSharp.Core.Operators
note signature is

1
'T list -> 'T list
1
2
3
let l = [5;4;3;2;1]

List.sort l |> printfn "%A"

sortBy uses generic comparison too but in keys

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 

type person = {name:string;age:int}
let persons = [{name="paul";age=28};{name="eric";age=56};{name="franck";age=21}]


// key is name
List.sortBy (fun p -> p.name) persons |> printfn "%A"
// key is age
List.sortBy (fun p -> p.age) persons |> printfn "%A"

// sort in reverse order using sortWith
List.sortWith (fun p1 p2 -> - compare p1.name p2.name) persons |> printfn "%A"
List.sortWith (fun p1 p2 -> - compare p1.age p2.age) persons |> printfn "%A"
By on 6/25/2009 3:03 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