So yesterday, while working through some F # code as part of the coding exercise, another developer noticed something interesting. We just did a quick piece of code to demonstrate the summation of the list. If I do this:
[1..100000] |> Seq.sum
I get the following error:
System.OverflowException: Arithmetic operation resulted in an overflow. at <StartupCode$FSI_0003> .$FSI_0003.main@ () Stopped due to error
However, if I do this:
[1..100000] |> List.reduce (+)
I get:
val it : int = 705082704
I understand that these two parts of the code must fulfill the same goal, they are very different. I'm just curious if there is a way to get List.reduce to throw an OverflowException instead of giving me a bad answer?
f #
Onorio catenacci
source share