Jensen's Device: Difference between revisions

Content added Content deleted
(added ocaml)
Line 109: Line 109:
=={{header|OCaml}}==
=={{header|OCaml}}==
{{trans|Python}}
{{trans|Python}}
<ocaml>let i = ref 42 (* initial value doesn't matter *)
<pre>
let i = ref 42 (* initial value doesn't matter *)


let sum' ref_i lo hi term =
let sum' ref_i lo hi term =
Line 124: Line 123:


let () =
let () =
Printf.printf "%f\n" (sum' i 1 100 (fun () -> 1. /. float !i))
Printf.printf "%f\n" (sum' i 1 100 (fun () -> 1. /. float !i))</ocaml>
</pre>
Output: 5.187378
Output: 5.187378