1 module Shows 2 (Shows, showsEmpty, showsConcat, showsString, showsChar, showsStar, 3 showsStarSep, showsSurround, showsListOf, showsParen, showsParenIf) 4 where 5 6 type Shows x = x -> ShowS 7 showsEmpty :: ShowS 8 showsEmpty r = r 9 showsConcat :: [ShowS] -> ShowS 10 showsConcat = foldr (.) showsEmpty 11 showsString :: Shows String 12 showsString = (++) 13 showsChar :: Shows Char 14 showsChar = (:) 15 showsStar :: Shows x -> Shows [x] 16 showsStar showsX xs = showsConcat (map showsX xs) 17 showsStarSep :: String -> Shows x -> Shows [x] 18 showsStarSep s showsX [] = showsEmpty 19 showsStarSep s showsX (x:xs) = showsX x 20 . showsConcat [showString s . showsX x' | x' <- xs] 21 showsSurround :: String -> Shows x -> String -> Shows x 22 showsSurround l showsX r x = showString l . showsX x . showString r 23 showsListOf :: Shows x -> Shows [x] 24 showsListOf showsX = showsSurround "[" (showsStarSep ", " showsX) "]" 25 showsParen :: ShowS -> ShowS 26 showsParen = showsSurround "(" id ")" 27 showsParenIf :: Bool -> ShowS -> ShowS 28 showsParenIf b xS = if b then showsParen xS else xS