Skip to content

Instantly share code, notes, and snippets.

@gsscoder
Last active December 28, 2019 20:39
Show Gist options
  • Save gsscoder/d91655c66a7b29de10f11f5ba21cd925 to your computer and use it in GitHub Desktop.
Save gsscoder/d91655c66a7b29de10f11f5ba21cd925 to your computer and use it in GitHub Desktop.
Haskell program to calculate factorial of a number
-- $ ./factorial 10
-- 3628800
import System.Environment
main = do
args <- getArgs
let n = args !! 0
putStrLn (show (factorial (read n)))
factorial :: (Integral a) => a -> a
factorial 0 = 1
factorial n = n * factorial (n - 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment