View difference between Paste ID: VZnMN6rh and
SHOW:
|
|
- or go back to the newest paste.
1 | let memoize (f : 'a -> 'b) = | |
2 | let cache = new Dictionary<'a, 'b>() | |
3 | ||
4 | let memoizedF x = | |
5 | match cache.TryGetValue(x) with | |
6 | | true, y -> y | |
7 | | false, _ -> | |
8 | let y = f x | |
9 | cache.Add(x, y) | |
10 | y | |
11 | ||
12 | memoizedF | |
13 |