Print a tic-tac-toe board I am currently learning Haskell and as an exercise, I am building a simple tic-tac-toe program. I start with
import Data.Vector

data Cell = Empty | X | O
type Board = Vector Cell

and then, to render the board:
render :: Board -&gt; IO ()
render b = do
    renderSep
    renderRow 0 b
    renderSep
    renderRow 1 b
    renderSep
    renderRow 2 b
    renderSep
  where
    renderSep :: IO ()
    renderSep = putStrLn &quot;+---+---+---+&quot;
    renderRow :: Int -&gt; Board -&gt; IO ()
    renderRow r b = do
        putStr &quot;| &quot; &gt;&gt; putStr (cellRepr $ getCell r 0 b)
        putStr &quot; | &quot; &gt;&gt; putStr (cellRepr $ getCell r 1 b)
        putStr &quot; | &quot; &gt;&gt; putStr (cellRepr $ getCell r 2 b)
        putStrLn &quot; |&quot;

How could I abstract my implementation so that there's less repetition? Especially in the main body of the render function. I thought of using sequence together with the list fmap (\x -&gt; renderRow x b &gt;&gt; renderSep) [0, 1, 2]. However, in this case I get a value of type IO [()] and not IO ().
I think a simple way to address the problem is by building the board first then printing it:
empty_row :: String
empty_row = &quot;+---+---+---+&quot;

board_repr :: type of b -&gt; String
board_repr b = empty_row + concat ( map (\x -&gt; (build_row x b) + empty_row ) [0, 1, 2] )

main = print (board_repr b)

Take this as pseudo-code pointing in an interesting direction by separating the concerns of building a representation and printing it.