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