|
|
|
|
|
by profquail
4537 days ago
|
|
Now here's the same example in F# (a functional language); it compiles into IL similar to that produced by your C# code. Which do you find more readable? module Program =
let n = 42
let rec sqrtGuesses x = seq {
yield x
let next_x = 0.5 * (x + (float n / x))
yield! sqrtGuesses next_x }
sqrtGuesses 1.0
|> Seq.pairwise
|> Seq.pick (fun (x, y) ->
if abs (x - y) < 1E-10 then Some y else None)
|> System.Console.WriteLine
System.Console.WriteLine (sqrt (float n))
|
|