Skip to content

Instantly share code, notes, and snippets.

Created September 2, 2016 04:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/dcb4f83dbbc543394b64ef7eb5bb0cf8 to your computer and use it in GitHub Desktop.
Save anonymous/dcb4f83dbbc543394b64ef7eb5bb0cf8 to your computer and use it in GitHub Desktop.
F# Factorial - Pattern Matching and Recursion
let factorial n =
let rec factorial' n acc =
match n with
| 0 -> acc
| _ -> factorial' (n - 1) (acc * n)
factorial' n 1
@jasondown
Copy link

Sample Usage:
[0..10] |> List.map factorial

val it : int list = [1; 1; 2; 6; 24; 120; 720; 5040; 40320; 362880; 3628800]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment