From 6cfbd0444981c074bae10a3cf72733bcb8597bef Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Thu, 16 Mar 2006 13:41:51 +0000 Subject: [PATCH] Fix a broken invariant Patch from #694, for the problem "empty is an identity for <> and $$" is currently broken by eg. isEmpty (empty<>empty)" --- Text/PrettyPrint/HughesPJ.hs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Text/PrettyPrint/HughesPJ.hs b/Text/PrettyPrint/HughesPJ.hs index df9642a..54ce7e1 100644 --- a/Text/PrettyPrint/HughesPJ.hs +++ b/Text/PrettyPrint/HughesPJ.hs @@ -606,8 +606,13 @@ mkUnion p q = p `union_` q -- --------------------------------------------------------------------------- -- Vertical composition @$$@ -p $$ q = Above p False q -p $+$ q = Above p True q +above_ :: Doc -> Bool -> Doc -> Doc +above_ p _ Empty = p +above_ Empty _ q = q +above_ p g q = Above p g q + +p $$ q = above_ p False q +p $+$ q = above_ p True q above :: Doc -> Bool -> RDoc -> RDoc above (Above p g1 q1) g2 q2 = above p g1 (above q1 g2 q2) @@ -651,8 +656,13 @@ nilAboveNest g k q | (not g) && (k > 0) -- No newline if no ove -- --------------------------------------------------------------------------- -- Horizontal composition @<>@ -p <> q = Beside p False q -p <+> q = Beside p True q +beside_ :: Doc -> Bool -> Doc -> Doc +beside_ p _ Empty = p +beside_ Empty _ q = q +beside_ p g q = Beside p g q + +p <> q = beside_ p False q +p <+> q = beside_ p True q beside :: Doc -> Bool -> RDoc -> RDoc -- Specification: beside g p q = p q -- 1.7.10.4