这是我的代码:
open System
let places = [ ("Grandchester", 552);
("Cambridge", 117900);
("Prague", 1188126); ]
let statusByPopulation = function
| n when n > 1000000 -> "City"
| n when n > 50000 -> "Town"
| _ -> "Village"
System.Console.WriteLine ( places |> List.map (fun (_, population) -> statusByPopulation population))
let print x =
Console.WriteLine (List.map (fun (_, population) -> statusByPopulation population) x) // what I'm trying to do
let something (x:(string * int) list) =
List.map (fun (_, population) -> statusByPopulation population) x; // checking what kinf of type it returns
let print: (string * int) list -> unit =
Console.WriteLine << List.map (fun (_, population) -> statusByPopulation population) // what I'm not allowed to do
System.Console.ReadKey () |> ignore
我想熟悉函数组合运算符的工作方式,但由于某种原因,F# 找不到函数的最佳重载...
在我明确声明参数的示例中,它将类型设置为val print : x:('a * int) list -> unit
,因此我使用组合运算符明确设置函数中的类型,<<
希望我能得到正确的结果......我没有......
然后我something
使用显式声明的参数类型创建函数,只是为了看看它会返回什么......它返回这个:val something : x:(string * int) list -> string list
所以它肯定会返回一个类型......一个字符串列表,我知道 Console.WriteLine 能够打印......那么为什么它告诉我它无法确定重载?