haskell: classic program fib.hs + source-order top-level binding (+2 tests, 388/388)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-25 08:53:47 +00:00
parent cd489b19be
commit 4ed7ffe9dd
4 changed files with 96 additions and 9 deletions

View File

@@ -0,0 +1,15 @@
-- 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