first100Ints = [1 .. 100]
allIntegers = [1 ..]
--defining infinite lists in instantaenous because it doesnt involve evaluation
--you can even use subsets of infinite lists and thats fine
--you can also try to print an infinite list but obviously that will never terminate.
--numbering characters in a string
numberChars :: String -> [(Int, Char)]
numberChars s = zip [1 .. n] s
where
n = length s
-- with infinite data structs:
numberChars :: String -> [(Int, Char)]
numberChars s = zip [1 ..] s
x = x+1
-- no error, it has not been evaluated at all yet.
-- printing it would cause an error, since x can't be evaluated.
fibonacciWrong = 0 : 1 : zipWith (+) fibonacciWrong fibonacciWrong
--no error until you try to evaluate something:
take 100 fibonacciWrong
[0, 1, 0, 2, 0 ,4 ,0, powers of 2...]
fibonacciWrong = zipWith (+) fibonacciWrong fibonacciWrong
--infinite loop, never prints anything.