count' :: [a] -> Int -> Int count' [] result = result count' (first:rest) result = count' rest (result + 1) count :: [a] -> Int count list = count' list 0 allNumbersStartingAt n = n : allNumbersStartingAt (n+1) take 5 (allNumbersStartingAt 0) take 11 (cycle ['S','O','S', '-']) divideByTen :: Fractional a => a -> a divideByTen = (/ 10) isUpperCase :: Char -> Bool isUpperCase = (`elem` ['A' .. 'Z']) applyTwice :: (a -> a) -> a -> a applyTwice f x = f (f x) applyTwice (+3) 10 applyTwice ("Hello, " ++) "who is there?" applyTwice (3:) [1] zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c] zipWith' f [] bs = [] zipWith' f as [] = [] zipWith' f (a:as) (b:bs) = f a b : zipWith' f as bs zipWith' (+) [1, 2, 3] [1, 2, 3] zipWith' (*) (replicate 4 3) [1..] zipWith' max [3,7,2] [4,1,6] zipWith' (++) ["James T. ", "", "Nyota "] ["Kirk", "Spock", "Uhura"] fibs = 0 : 1 : zipWith' (+) fibs (tail fibs) fibs :: [Integer] fibs = 0 : 1 : zipWith (+) fibs (tail fibs) map :: (a -> b) -> [a] -> [b] map _ [] = [] map f (x:xs) = f x : map f xs map ("Beam me up, " ++) ["Kirk", "Spock", "Scotty"] map (replicate 3) [1, 2, 3] map fst [('A', 'B'), ('C', 'D'), ('E', 'F')] map snd [('A', 'B'), ('C', 'D'), ('E', 'F')] filter' :: (a -> Bool) -> [a] -> [a] filter' _ [] = [] filter' p (x:xs) | p x = x : filter' p xs | otherwise = filter' p xs filter (>3) [1,5,3,2,1,6,4,3,2,1] filter even [1,5,3,2,1,6,4,3,2,1] filter (`elem` ['a'..'z']) "Beam me up, Scotty!" filter (`elem` ['A'..'Z']) "Beam me up, Scotty!"