Published on 28 April 2022 (Updated: 25 September 2022)

Welcome to the Fibonacci 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.Readfibonacci::Int->[Integer]fibonacci=flip(take)fibsfibs::[Integer]fibs=1:1:zipWith(+)fibs(tailfibs)headMaybe::[a]->MaybeaheadMaybe[]=NothingheadMaybe(x:xs)=Justx-- Takes a list of values and returns a list of strings in the format "ONE_BASED_INDEX: VALUE"printWithIndex::(Showa)=>[a]->[[Char]]printWithIndex=zipWith(\ix->(showi)++": "++(showx))[1..]-- Prints out the first N numbers from the fibonacci sequence-- where N equals to the first command line argument.main::IO()main=doargs<-getArgsletn=headMaybeargscasen>>=readMaybeofNothing->putStrLn"Usage: please input the count of fibonacci numbers to output"Justn->mapM_(putStrLn)$(printWithIndex.fibonacci)n

Note: The solution shown above is the current solution in the Sample Programs repository as of Apr 07 2019 00:40:32. The solution was first committed on Oct 15 2018 18:50:33. As a result, documentation below may be outdated.