Summations and products in F#
Starting with summation,


let summation func low high =
    let function_result_set: int list = [for x in low..high do yield x |&gt; func]
    let result = function_result_set |&gt; List.sum
    result



First of all, we can remove result

let summation func low high =
    let function_result_set: int list = [for x in low..high do yield x |&gt; func]
    function_result_set |&gt; List.sum


Next, we don't need to construct a list containing func(low) .. func(high); we can instead operate over a sequence, meaning we don't have to have all those values in memory at once.

let summation func low high =
    let function_result_set = Seq.map func { low .. high }
    function_result_set |&gt; Seq.sum


Now we can make it a bit more succinct

let summation func low high =
    Seq.map func { low .. high } |&gt; Seq.sum


Finally, we can make it more generic by using statically resolved type parameters. At the moment, if we have a call to summation like this:

printfn "%d" &lt;| summation id 1 10


then summation will be constrained to be of type (int -&gt; int) -&gt; int -&gt; int -&gt; int. We can fix this by making the function inline:

let inline summation func low high =
    Seq.map func { low .. high } |&gt; Seq.sum


Now  summation has type ('a -&gt; 'b) -&gt; 'a -&gt; 'a -&gt; 'b and the following code will compile:

printfn "%d" &lt;| summation id 1 10
printfn "%f" &lt;| summation id 1.0 10.0


Similar comments hold for product, but with two additional things:


To make it generic we need to get the One property of the type ^a, and
I've used the checked version of * to check for overflow




let inline product func low high : ^a =
    Seq.map func { low .. high } |&gt; Seq.fold Checked.(*) LanguagePrimitives.GenericOne&lt; ^a &gt;