Created
March 3, 2016 12:38
-
-
Save Tyralion/185821cd17efc39ef26e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module MyFib where | |
| fibonacci :: Integer -> Integer | |
| fibonacci n | n == 0 = 0 | |
| | n == 1 = 1 | |
| | n > 0 = helper 0 1 n | |
| | n < 0 = ((-1) ^ (-n+1)) * helper 0 1 (-n) | |
| helper acc1 acc2 0 = acc1 | |
| helper acc1 acc2 n = helper (acc2) (acc2 + acc1) (n - 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment