Published on 28 April 2022 (Updated: 05 February 2023)

Welcome to the Factorial in Haskell page! Here, you’ll find the source code for this program as well as a description of how the program works.

Current Solution

moduleMainwhereimportSystem.EnvironmentimportText.Readfactorial::Integer->Integerfactorial0=1factorialn=n*factorial(n-1)headMaybe::[a]->MaybeaheadMaybe[]=NothingheadMaybe(x:xs)=Justxmain::IO()main=doargs<-getArgsletn=headMaybeargscasen>>=readMaybeofNothing->putStrLn"Usage: please input a non-negative integer"Justn|n<0->putStrLn"Usage: please input a non-negative integer"|n<=250000->putStrLn$take10$show$factorialn|otherwise->putStrLn$"!"++(shown)++" is out of the reasonable bounds for calculation"