Add compatibility gorp for GHC 6.6.1.
[match/match.git] / program / Formatter.hs
CommitLineData
967c39ef
MM
1module Formatter where
2import Data.List
3
7b8c0e4e
MM
4#if __GLASGOW_HASKELL__ <= 606
5intercalate xs xss = concat (intersperse xs xss)
6#endif
7
967c39ef
MM
8padWith :: a -> Int -> [a] -> [a]
9padWith _ 0 l = l
10padWith e n [] = replicate n e
11padWith e (n+1) (h:t) = h:(padWith e n t)
12
13formatTable :: [[String]] -> String
14formatTable cells =
15 let columnWidths = map (\col -> maximum $ map length col)
16 $ transpose cells in
17 intercalate "\n" $
18 map (\row ->
19 let rowCells = zipWith (padWith ' ') columnWidths row in
20 intercalate " " rowCells
21 ) cells