title: How to properly indent blocks using HughesPJ's pretty printing library?
body: <p>I have a following programming language grammar:</p>
  <pre><code>data Expr = ...
  
  data Stmt = SExpr Expr | SBlock Block | SLet Fundef | ...
  
  data Block = Block [Stmt]
  
  data Fundef = Fundef String [String] Block
  
  data TopDef = TopFun Fundef
  </code></pre>
  <p>With following example syntax:</p>
  <pre><code>function long_function_name () = {
    let g() = {
      {
         h()
      };
      3
    } 
  }
  </code></pre>
  <hr />
  <p>I am trying to use HughesPJ <code>pretty</code> library to create a pretty printer for this language. My attempts so far look like:</p>
  <pre><code>instance Pretty Stmt where
    pPrint = \case
      SExpr e -&gt; pPrint e
      SBlock b -&gt; pPrint b
      SLet f -&gt; text &quot;let&quot; &lt;+&gt; pPrint f
  
  instance Pretty Block where
    pPrint (Block stmts) = lbrace $+$
      nest 2 (vcat (punctuate semi (map pPrint stmts))) $+$ 
      rbrace
  
  instance Pretty Fundef where
    pPrint (Fundef name args body) = pPrint name  &lt;&gt; parens (...) &lt;+&gt; text &quot;=&quot; &lt;+&gt; pPrint body
  
  instance Prettty TopDef where
    pPrint (TopFun f) = text &quot;function&quot; &lt;+&gt; pPrint f
  </code></pre>
  <p>The problem is, I want to have <code>{</code> in the same line as the function declaration, but it always makes the indentation of the following lines relative to the column of the bracket instead of being absolute. Should be visible in the pretty print of the example above;</p>
  <pre><code>function long_function_name () = {
                                     let g() = {
                                                 {
                                                   h()
                                                 };
                                                 3
                                               } 
  }
  </code></pre>
  <p>Why does it happen and how should I tackle this problem? I would like to avoid as much code duplication as possible.</p>