2026-08-20
Infinite.hs
main :: IO ()
main = do
let nats = [0..]
let pairs = zip nats "ab"
print pairs
nats is an infinite list. Does this terminate, and what does it print?
Answer
Yes, it terminates: [(0,'a'),(1,'b')]. zip stops as soon as either list runs out — "ab" has only 2 elements, so zip only ever demands the first 2 elements of the infinite nats, then stops. Laziness means the infinite list is never a problem as long as something finite bounds the consumption.