Published on 16 November 2018 (Updated: 16 November 2018)

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"