Files
rose-ash/lib/haskell/tests/programs/fib.hs
giles 4ed7ffe9dd
Some checks are pending
Test, Build, and Deploy / test-build-deploy (push) Waiting to run
haskell: classic program fib.hs + source-order top-level binding (+2 tests, 388/388)
2026-04-25 08:53:47 +00:00

16 lines
524 B
Haskell

-- fib.hs — infinite Fibonacci stream.
--
-- The classic two-line definition: `fibs` is a self-referential
-- lazy list built by zipping itself with its own tail, summing the
-- pair at each step. Without lazy `:` (cons cell with thunked head
-- and tail) this would diverge before producing any output; with
-- it, `take 15 fibs` evaluates exactly as much of the spine as
-- demanded.
zipPlus (x:xs) (y:ys) = x + y : zipPlus xs ys
zipPlus _ _ = []
myFibs = 0 : 1 : zipPlus myFibs (tail myFibs)
result = take 15 myFibs