Created
November 15, 2009 21:47
-
-
Save Ball/235497 to your computer and use it in GitHub Desktop.
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
let fibonacci n = | |
let rec fib_cps n cont = | |
match n with | |
| 0 -> (cont 0) // <-- even the base cases need to keep the promise | |
| 1 -> (cont 1) | |
| _ -> (fib_cps (n-1) (fun a -> fib_cps (n-2) (fun b -> cont(a+b)) ) ) | |
fib_cps n (fun x -> x) // <- this anon function is our base continuation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment