Skip to content

Instantly share code, notes, and snippets.

@Tom01098
Created April 27, 2019 15:12
Show Gist options
  • Save Tom01098/6645a46d294492c489b03860fa7469dc to your computer and use it in GitHub Desktop.
Save Tom01098/6645a46d294492c489b03860fa7469dc to your computer and use it in GitHub Desktop.
Factorial implemented in F#
// Get the factorial of an integer.
let factorial n =
// Actual recursive factorial implementation.
let rec f n =
match n with
| 0 -> 1
| _ -> n * f (n - 1)
// Validate that n isn't negative
match n with
| _ when n < 0 -> None
| _ -> Some (f n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment