module Main where eng_commafy :: (Show a) => [a] -> String eng_commafy x | length x > 2 = foldl1 (commacat) init_as_show ++ ", and " ++ last_show where commacat x y = x ++ ", " ++ y init_as_show = map (show) (init x) last_show = show (last x) eng_commafy x | length x == 2 = (show (head x)) ++ " and " ++ (show (last x)) eng_commafy x | length x == 1 = show (head x) eng_commafy [] = "" main = do putStrLn (eng_commafy [1..10]) putStrLn (eng_commafy [1,2]) putStrLn (eng_commafy [1])