The type inference in F# works from the left to the right - this means that the compiler uses information available earlier in the program to determine types of expressions later in the program (this is a slight simplification, but it is the general idea).
So in your code, when you write:
Console.WriteLine << List.map (fun (_, population) -> statusByPopulation population)
.. the compiler does not propagate the information about the type of function input through the List.map
call back to the WriteLine
call. This also explains why forward chaining and composition are generally more useful in F#. The following works:
List.map (fun (_, population) -> statusByPopulation population) >> Console.WriteLine
To get your original code working, you could provide some minimal amount of information that is needed to determine that the right WriteLine
overload is the one taking object
. If you tell the compiler that it needs to take a list of something, then it can choose the right overload:
(Console.WriteLine:list<_> -> unit) << List.map (fun (_, population) ->
statusByPopulation population)