Skip to content

Instantly share code, notes, and snippets.

@gallais
Created December 6, 2014 21:43
Show Gist options
  • Save gallais/bf1d202cb13c9248b3c3 to your computer and use it in GitHub Desktop.
Save gallais/bf1d202cb13c9248b3c3 to your computer and use it in GitHub Desktop.
factorial using continuations
let factorial n =
let rec loop n k = match n with
| 0 -> k 1
| n -> loop (n-1) (fun v -> k (v * n)) in
loop n (fun x -> x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment