diff options
Diffstat (limited to 'compiler/utils/Pretty.hs')
-rw-r--r-- | compiler/utils/Pretty.hs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/compiler/utils/Pretty.hs b/compiler/utils/Pretty.hs index 4aae2c8c53..74d69f23d0 100644 --- a/compiler/utils/Pretty.hs +++ b/compiler/utils/Pretty.hs @@ -180,7 +180,7 @@ module Pretty ( sep, cat, fsep, fcat, nest, - hang, punctuate, + hang, hangNotEmpty, punctuate, -- * Predicates on documents isEmpty, @@ -563,6 +563,12 @@ nest k p = mkNest k (reduceDoc p) hang :: Doc -> Int -> Doc -> Doc hang d1 n d2 = sep [d1, nest n d2] +-- | Apply 'hang' to the arguments if the first 'Doc' is not empty. +hangNotEmpty :: Doc -> Int -> Doc -> Doc +hangNotEmpty d1 n d2 = if isEmpty d1 + then d2 + else hang d1 n d2 + -- | @punctuate p [d1, ... dn] = [d1 \<> p, d2 \<> p, ... dn-1 \<> p, dn]@ punctuate :: Doc -> [Doc] -> [Doc] punctuate _ [] = [] |