renderExpr :: Expr -> Serialized
renderExpr = renderPrec False
  where
    renderPrec _ (VarE v) = pretty v
    renderPrec _ (LitE lit) = renderLit lit
    renderPrec p other | p = parens r
                       | otherwise = r
      where
        r = case other of
              LetE var e b -> "let" <+> renderDestr var <+> "=" <+> renderExpr e <+> "in" <+> renderExpr b
              IfE b t e -> "if" <+> renderExpr b <+> "then" <+> renderExpr t <+> "else" <+> renderExpr e
              ApplyE fun arg -> renderPrec False fun <+> renderPrec True arg
              DoE b ->  "do" <> line <> indent 2 (renderStmt b)
              LambdaE l -> renderFunction l
renderExpr :: Expr -> Serialized
renderExpr = renderPrec False
  where
    renderPrec _ (VarE v) = pretty v
    renderPrec _ (LitE lit) = renderLit lit
    renderPrec p other | p = parens r
                       | otherwise = r
      where
        r = case other of
              LetE var e b -> "let" <+> renderDestr var <+> "=" <+> renderExpr e <+> "in" <+> renderExpr b
              IfE b t e -> "if" <+> renderExpr b <+> "then" <+> renderExpr t <+> "else" <+> renderExpr e
              ApplyE fun arg -> renderPrec False fun <+> renderPrec True arg
              DoE b ->  "do" <> line <> indent 2 (renderStmt b)
              LambdaE l -> renderFunction l
renderExpr = renderPrec False
  where
    renderPrec _ (VarE v) = pretty v
    renderPrec _ (LitE lit) = renderLit lit
    renderPrec p other | p = parens r
                       | otherwise = r
      where
        r = case other of
              LetE var e b -> "let" <+> renderDestr var <+> "=" <+> renderExpr e <+> "in" <+> renderExpr b
              IfE b t e -> "if" <+> renderExpr b <+> "then" <+> renderExpr t <+> "else" <+> renderExpr e
              ApplyE fun arg -> renderPrec False fun <+> renderPrec True arg
              DoE b ->  "do" <> line <> indent 2 (renderStmt b)
              LambdaE l -> renderFunction l