Skip to content

Instantly share code, notes, and snippets.

@palladin
Created March 3, 2013 13:00
Show Gist options
  • Save palladin/5076013 to your computer and use it in GitHub Desktop.
Save palladin/5076013 to your computer and use it in GitHub Desktop.
GC Friendly Fixpoint
#time
let rec Y f x = f (Y f) x
let Y' f x =
let r = ref Unchecked.defaultof<'a -> 'b>
r := (fun x -> f !r x)
f !r x
let iter f x = if x = 100000000 then x else f (x + 1)
// Real: 00:00:01.504, CPU: 00:00:01.497, GC gen0: 572, gen1: 1, gen2: 0
Y iter 1
// Real: 00:00:00.769, CPU: 00:00:00.780, GC gen0: 0, gen1: 0, gen2: 0
Y' iter 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment