Published on 15 October 2018 (Updated: 07 April 2019)

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