Skip to content

Instantly share code, notes, and snippets.

@Radagaisus
Created April 28, 2011 12:21
Show Gist options
  • Save Radagaisus/946245 to your computer and use it in GitHub Desktop.
Save Radagaisus/946245 to your computer and use it in GitHub Desktop.
leaky.hs
-- Fibonacci Sequence Abstraction
fib :: Integer -> Integer
fib 0 = 1
fib 1 = 1
fib x = fib (x - 1) + fib (x - 2)
-- Another Fibonacci Sequence Abstraction
fibTuple:: (Integer, Integer, Integer) -> (Integer, Integer, Integer)
fibTuple (x, y, 0) = (x, y, 0)
fibTuple (x, y, index) = fibTuple(y, x + y, index - 1)
fibUtil :: (Integer, Integer, Integer) -> Integer
fibUtil (x, y, z) = x
fib :: Integer -> Integer
fib x = fibUtil (fibTuple (0, 1, x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment