import Prelude {- Prelude has null :: [a] -> Bool that retunrs True for empty lists, length :: [a] -> Int to get the length of litss, and sum :: [Int] -> Int to get the sum of elements in the list so these implementations could be simpler still -} {-| An example list of integers 1 - 4 -} ex01 :: [Int] ex01 = [1,2,3,4] {-| Makes a string of repeated strings -} makeStringOf :: String -> Int -> String makeStringOf _ 0 = "" makeStringOf s n = s ++ (makeStringOf s (n - 1)) main :: IO () main = do putStrLn $ "ex1 : " ++ (show ex01) putStrLn $ "ex1 length : " ++ (show (foldl (\acc _ -> acc + 1) 0 ex01)) putStrLn $ "doubled ex1 : " ++ (show (map (2 *) ex01)) putStrLn $ "sum ex1 : " ++ (show (foldl (+) 0 ex01)) putStrLn $ "histogram : " ++ (show (map (makeStringOf "*") ex01)) -- bonus - mapping using foldr for a right fold... putStrLn $ "doubled ex1 : " ++ (show (foldr (\x acc -> (2 * x):acc) [] ex01))