Memoization in OCaml?
问题 It is possible to improve "raw" Fibonacci recursive procedure Fib[n_] := If[n < 2, n, Fib[n - 1] + Fib[n - 2]] with Fib[n_] := Fib[n] = If[n < 2, n, Fib[n - 1] + Fib[n - 2]] in Wolfram Mathematica. First version will suffer from exponential explosion while second one will not since Mathematica will see repeating function calls in expression and memoize (reuse) them. Is it possible to do the same in OCaml? How to improve let rec fib n = if n<2 then n else fib (n-1) + fib (n-2);; in the same