Skip to content

Instantly share code, notes, and snippets.

@Tyralion
Created March 3, 2016 12:38
Show Gist options
  • Select an option

  • Save Tyralion/185821cd17efc39ef26e to your computer and use it in GitHub Desktop.

Select an option

Save Tyralion/185821cd17efc39ef26e to your computer and use it in GitHub Desktop.
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