Copyright © 2024 SingChun Lee Bucknell University. All rights reserved. Sites developed using revealjs.
[1 .. 10] -- Python: range(1, 11)
[2, 4 .. 10] -- Python: range(2, 11, 2)
[1 ..] -- [1, 2, 3, 4, ...]
[1, 1 ..] -- [1, 1, 1, 1, ...]
[2, 4 ..] -- [2, 4, 6, 8, ...]
[4, 8 ..] -- [4, 8, 12, 16, ...]
take :: Int -> [a] -> [a]
take _ [] = []
take 0 _ = []
take n (h:t) = h : take (n - 1) t
-- the below gets [3, 6, 9, 12, 15]
take 5 [3, 6, ..]
plus2 :: Int -> [Int]
plus2 n = n : plus (n + 2)
odds :: [Int]
odds = plus2 1
evens :: [Int]
evens = plus2 2
integers = [x | x <- [1 ..]]
odds = [x | x <- [1 ..], mod x 2 == 1]
squares = [x^2 | x <- [1 ..]]
nextfib :: Int -> Int -> [Int]
nextfib x y = (x + y) : nextfib y (x + y)
fibs :: [Int]
fibs = [1, 1] ++ nextfib 1 1
sieve :: [Int] -> [Int]
sieve (x:xs) = x :
seive [y | y <- xs, mod y x /= 0]
primes :: [Int]
primes = sieve [2 ..]