Last active
May 6, 2022 18:03
-
-
Save johnwesonga/eb427b0fc10c83c9e3241f13042ca03d to your computer and use it in GitHub Desktop.
Factorial in Elm
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
import Html exposing (text) | |
fact : Int -> Int | |
fact n = | |
case n of | |
0 -> 1 | |
1 -> 1 | |
_ -> n * fact(n-1) | |
factorial : Int -> Int | |
factorial n = | |
if n < 1 then | |
1 | |
else | |
n * factorial(n-1) | |
main = | |
fact 3 |> String.fromInt |> text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
facts first