Created
March 28, 2017 20:53
-
-
Save henrytill/1d06b5171e3bc0c01f23af43275c0130 to your computer and use it in GitHub Desktop.
Landin's Knot
This file contains hidden or 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
(** "Landin's Knot" - implements recursion by backpatching *) | |
let landins_knot f = | |
let r = ref (fun x -> assert false) in | |
let fixedpoint = f (fun x -> !r x) in | |
r := fixedpoint; | |
fixedpoint | |
let factorial = | |
let g f x = | |
if x = 0 then | |
1 | |
else | |
x * f (x - 1) | |
in | |
landins_knot g |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment