We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
With recursion. Example of code:
using System; using System.Collections.Generic; using static Memes; var fib = Memoize<int, int>((n, fib) => n switch { <= 1 => 1, var m => fib(n - 1) + fib(n - 2) }); Console.WriteLine(fib(40)); public static class Memes { public static Func<TIn, TOut> Memoize<TIn, TOut>(Func<TIn, Func<TIn, TOut>, TOut> func) { var dic = new Dictionary<TIn, TOut>(); Func<TIn, TOut> rec = null; rec = tin => { if (dic.TryGetValue(tin, out var res)) return res; res = func(tin, rec); dic[tin] = res; return res; }; return rec; } }
public static Func<TIn, TOut> Memoize<TIn, TOut>(Func<TIn, Func<TIn, TOut>> func); public static (Func<TIn1, TOut1>, Func<TIn2, TOut2>) Memoize<TIn1, TIn2, TOut1, TOut2>(Func<TIn1, Func<TIn1, TOut1>, Func<TIn2, TOut2>, TOut1> func1, Func<TIn2, Func<TIn1, TOut1>, Func<TIn2, TOut2>, TOut2> func2); ...
The text was updated successfully, but these errors were encountered:
Re-consideration with #25: make
prec : (a * (a -> b) -> b) -> a -> b mrec : (a * (a -> b) -> b) -> a -> b
Where mrec is a memoizing recursor
mrec
Sorry, something went wrong.
No branches or pull requests
With recursion. Example of code:
PoC
API
The text was updated successfully, but these errors were encountered: