-- Shows how various functions are implemented -- (or could be implemented) in the Standard Prelude. -- Probably want to read this rather than loading it. length :: [a] -> Int length [] = 0 length (x:xs) = 1 + length xs head :: [a] -> a head (x:_) = x tail :: [a] -> [a] tail (_:xs) = xs zip :: [a] -> [b] -> [(a,b)] zip (x:xs) (y:ys) = (x, y) : zip xs ys zip _ _ = [] map :: (a -> b) -> [a] -> [b] map f (x:xs) = f x : map f xs map f [] = [] zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] zipWith f (x:xs) (y:ys) = f x y : zipWith f xs ys zipWith _ _ _ = [] foldr :: (a -> b -> b) -> b -> [a] -> b foldr op init [] = init foldr op init (x:xs) = x `op` foldr op init xs foldl :: (a -> b -> a) -> a -> [b] -> a foldl op init [] = init foldl op init (x:xs) = foldl op (init `op` x) xs foldr (:) [] list -> list -- What is signature? consToHead x list = (x : head list) : list suffixes xs = foldr consToHead [[]] xs