Combine memoization and tail-recursion
As always, continuations yield an elegant tailcall solution: open System.Collections.Generic let cache = Dictionary<_,_>() // TODO move inside let memoizedTRFactorial = let rec fac n k = // must make tailcalls to k match cache.TryGetValue(n) with | true, r -> k r | _ -> if n=0 then k 1 else fac (n-1) (fun r1 … Read more