Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Haskell #165

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Haskell/haskell_fibonacci.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sum' :: Int -> Int
sum' 0 = 1
sum' 1 = 1
sum' x = sum' (x-1) + sum' (x-2)

fibonacci :: [Int]
fibonacci = [sum' x | x <- [0,1..]]
1 change: 1 addition & 0 deletions Languages.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Hello there!!
- C++
- Dart
- Go
- Haskell
- Java
- Javascript
- Kotlin
Expand Down
15 changes: 15 additions & 0 deletions fibonacci_series/Haskell/haskell_fibonacci.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Creating the summing function
-- Made with pattern matching
sum' :: Int -> Int
sum' 0 = 1
sum' 1 = 1
sum' x = sum' (x-1) + sum' (x-2)

-- Recursive function to create as many elements as you need
-- Since Haskell is lazy, it will only evaluate as many values as you are needing it to
neverEndingFibonacci :: [Int]
neverEndingFibonacci = [sum' x | x <- [0,1..]]

-- To comply with the outlined rules in CONTRIBUTING.md
-- returns x amount of the sequence in a list
fibonacci x = take x neverEndingFibonacci