Something like this should have the same effect:
let sum = list |> Seq.map System.Int32.Parse |> Seq.sum
F # doesn't seem to support invoking a method on an int , so I had to use System.Int32 instead.
In F #, the seq type is an alias for .NET IEnumerable , so this code works with arrays, lists, etc.
Pay attention to the use of Parse in the " Parse " style - a function without its argument can be used directly as an argument to another function that expects this type. In this case, Seq.map has this type:
('a -> 'b) -> seq<'a> -> seq<'b>
And since System.Int32.Parse is of type string -> int , Seq.map System.Int32.Parse is of type seq<string> -> seq<int> .
Ganesh sittampalam
source share