Created
April 27, 2019 15:12
-
-
Save Tom01098/6645a46d294492c489b03860fa7469dc to your computer and use it in GitHub Desktop.
Factorial implemented in F#
This file contains 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
// 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