Created
April 2, 2018 14:11
-
-
Save voronoipotato/050d136b6f8fd47757c3ef41ce46174c to your computer and use it in GitHub Desktop.
Decent Memoize function in F#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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