Haskell: Draw tabulated data given header and rows as lists I need to draw tabulated data given a header as list and rows as list of lists
This is what I came up with. I wouldn't say that I like it much.
Could you please have a look if it can be done better (I am sure it can) and generally point to any error and possible optimization. Maybe someone has done exact same thing before. Thanks.

import Data.Text (justifyLeft, unpack, pack)
import Data.Char (toUpper)

tDraw :: [String] -&gt; [[String]] -&gt; IO()
tDraw h rs = do
  putChar '\n'
  -- draw header
  mapM_ (\x -&gt; putStr x) header
  putChar '\n'
  -- draw separator line
  mapM_ (\x -&gt; putChar x) (replicate (cell * length header) '=')
  putChar '\n'
  -- draw rows
  mapM_ (\x -&gt; row cell x) rs
  where
    cell = if l &lt; 10 then 12 else l + 2
           where l = (maximum . map (\x -&gt; length x) . concat) (h:rs)
    header = map (\x -&gt; strToUp $ unpack $ justifyLeft cell ' ' (pack x)) h
             where strToUp = map (\c -&gt; toUpper c)
    row n l  = do
      mapM_ (\x -&gt; putStr $ unpack $ justifyLeft n ' ' (pack x)) l
      putChar '\n'
It might make sense to use a pretty-printing library to do this.  You can use pretty along with the extension pretty-ncols package; or possibly boxes would work as it's aimed at more 2D textual information.