Last active
August 29, 2015 14:27
-
-
Save imetallica/f3859378c4dcad989b55 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| -module(factorial). | |
| -export[fac1/1, fac2/1]. | |
| %% With guards | |
| fac1(x) when x <= 0 -> 1; | |
| fac1(x) when x > 0 -> x * fac(x-1). | |
| %% With pattern-matching [does not handle x < 0] | |
| fac2(x) -> | |
| case x of | |
| 0 -> 1; | |
| _ -> x * fac(x-1). | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment