Advertisement
Guest User

Untitled

a guest
Oct 1st, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.27 KB | None | 0 0
  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.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement