Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Oct 1st, 2011  |  syntax: F#  |  size: 0.27 KB  |  hits: 123  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.