Skip to content

Instantly share code, notes, and snippets.

@voronoipotato
Created April 2, 2018 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voronoipotato/050d136b6f8fd47757c3ef41ce46174c to your computer and use it in GitHub Desktop.
Save voronoipotato/050d136b6f8fd47757c3ef41ce46174c to your computer and use it in GitHub Desktop.
Decent Memoize function in F#
let memoize f =
let cache = ref Map.empty
fun x ->
match (!cache).TryFind(x) with
| Some res -> res
| None ->
let res = f x
cache := (!cache).Add(x,res)
res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment