Fibonacci sequence: Difference between revisions
→{{header|Haskell}}
CRGreathouse (talk | contribs) (→{{header|PARI/GP}}: sinh) |
|||
Line 7,399:
(0, 1)
[1 .. n]</syntaxhighlight>
==== As an unfold ====
Create an infinite list of integers using an unfold. The nth fibonacci number is the nth number in the list.
<syntaxhighlight lang="haskell">import Data.List (unfoldr)
fibs :: [Integer]
fibs = unfoldr (\(x, y) -> Just (x, (y, x + y))) (0, 1)
fib n :: Integer -> Integer
fib n = fibs !! n</syntaxhighlight>
=== With matrix exponentiation ===
|