I thought the tailcall annotation might help but it did not.
[<TailCall>]
let rec sum n accum = if n = 65535 then accum else sum (n - 1) (accum + (1. / (float (n * n))))
let pi_approx =
sum 80000 0.
printf "%f" pi_approx
Yes, that’s a silly typo that I didn’t bother to correct after I identified the divide by zero error, as I felt that a finite real number was a much superior approximation to pi than Infinity is
It is actually pi squared, not pi, the window to edit the original code has lapsed but the correct code should modify the last line to take the square root of the whole expression.