0

我无法理解。如何找到最常用的名称,例如

type person = {name:string; surname:string}

let persons=[{name:"Jack";surname:"YYY"};
             {name:"Joe";surname:"XYX"};
             {name:"Jack";surname:"XXY"}]
4

1 回答 1

7
// You have to use '=' instead of ':' between field names and field values
let persons = 
    [ {name = "Jack"; surname = "YYY"};
      {name = "Joe"; surname = "XYX"};
      {name = "Jack"; surname = "XXY"} ]

// val it : string = "Jack"
persons |> Seq.countBy (fun {name = s} -> s)
        |> Seq.maxBy snd
        |> fst
于 2012-12-11T12:17:32.597 回答