Skip to content

Instantly share code, notes, and snippets.

@Ball
Created November 15, 2009 21:47
Show Gist options
  • Save Ball/235497 to your computer and use it in GitHub Desktop.
Save Ball/235497 to your computer and use it in GitHub Desktop.
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