Some checks are pending
Test, Build, and Deploy / test-build-deploy (push) Waiting to run
16 lines
524 B
Haskell
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
|