Skip to content

Instantly share code, notes, and snippets.

@tLewisII
Last active December 25, 2015 18:09
Show Gist options
  • Save tLewisII/7017887 to your computer and use it in GitHub Desktop.
Save tLewisII/7017887 to your computer and use it in GitHub Desktop.
Fibonacci sequence generator in Haskell. Given an upper bounds, will return a list of all numbers in the sequence that are <= the upper bounds.
module Main where
loop :: Integer -> [Integer] -> Integer -> Integer -> [Integer]
loop upper list cur prev
| (cur == upper) = list ++ [cur]
| (cur > upper) = list
| otherwise = loop upper (list ++ [cur]) (cur + prev) cur
fibSeq :: Integer -> [Integer]
fibSeq 0 = [0]
fibSeq 1 = [0,1]
fibSeq n = loop n [0] 1 0
main = print (fibSeq 10000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment