
It's a long time since I looked at this library. If you two can agree on what needs to be done, I'll gladly execute the change! Simon | -----Original Message----- | From: libraries-bounces@haskell.org [mailto:libraries-bounces@haskell.org] On Behalf Of Christian | Maeder | Sent: 24 November 2005 18:05 | To: Conal Elliott | Cc: libraries@haskell.org | Subject: Re: lawbreakers in Text.PrettyPrint.HughesPJ | | Conal Elliott wrote: | > Or the combinators (<>, $$, etc) might take care to build their results | > in reduced form, which seems to be the strategy that "nest" takes. | | maybe that is possible, too (as now an extra call of reduceDoc for | isEmpty is done). Fortunately isEmpty is rarely used, and if it is used | the original input is usually thrown away. | | > BTW, there's an invariant comment (about Doc, I think) that says "An | > empty document is always represented by @Empty@." If the combinators | > aren't going to ensure that's true, then probably the comment should be | > removed or fixed. | | The comment only seems to apply to RDoc that don't have Above or Beside | (at least on the top-level). | | Christian | _______________________________________________ | Libraries mailing list | Libraries@haskell.org | http://www.haskell.org/mailman/listinfo/libraries

Simon Peyton-Jones wrote:
It's a long time since I looked at this library. If you two can agree on what needs to be done, I'll gladly execute the change!
I've tried both versions, without noticing a difference. So take the following patch (as suggested by Conal). Cheers Christian -- --------------------------------------------------------------------------- -- Vertical composition @$$@ -p $$ q = Above p False q -p $+$ q = Above p True q +above_ :: Doc -> Bool -> Doc -> Doc +above_ Empty _ q = q +above_ p _ Empty = p +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) @@ -607,8 +611,13 @@ -- --------------------------------------------------------------------------- -- Horizontal composition @<>@ -p <> q = Beside p False q -p <+> q = Beside p True q +beside_ :: Doc -> Bool -> Doc -> Doc +beside_ Empty _ q = q +beside_ p _ Empty = p +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 <g> q

Christian Maeder wrote:
@@ -607,8 +611,13 @@
Myline number may be wrong, because I used an older version of the module. After the introduction of above_ and beside_ it also makes sense to move the call of reduceDoc to the last argument (and remove this calls in reduceDoc and above). The patch for this is below. I cannot observe speed differences, though. Christian @@ -461,8 +461,8 @@ type RDoc = Doc reduceDoc :: Doc -> RDoc -reduceDoc (Beside p g q) = beside p g (reduceDoc q) -reduceDoc (Above p g q) = above p g (reduceDoc q) +reduceDoc (Beside p g q) = beside p g q +reduceDoc (Above p g q) = above p g q reduceDoc p = p @@ -562,15 +562,15 @@ above_ :: Doc -> Bool -> Doc -> Doc above_ Empty _ q = q above_ p _ Empty = p -above_ p g q = Above p g q +above_ p g q = Above p g (reduceDoc 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) -above p@(Beside _ _ _) g q = aboveNest (reduceDoc p) g 0 (reduceDoc q) -above p g q = aboveNest p g 0 (reduceDoc q) +above p@(Beside _ _ _) g q = aboveNest (reduceDoc p) g 0 q +above p g q = aboveNest p g 0 q aboveNest :: RDoc -> Bool -> Int -> RDoc -> RDoc -- Specfication: aboveNest p g k q = p $g$ (nest k q) @@ -614,7 +614,7 @@ beside_ :: Doc -> Bool -> Doc -> Doc beside_ Empty _ q = q beside_ p _ Empty = p -beside_ p g q = Beside p g q +beside_ p g q = Beside p g (reduceDoc q) p <> q = beside_ p False q p <+> q = beside_ p True q

Christian Maeder wrote:
I've tried both versions, without noticing a difference. So take the following patch (as suggested by Conal).
I became a problem with my (Conal's) suggested patch on a mac. When compiled with optimization the code was so blown up that it could no longer be linked on a mac. (The problem does not occur if only isEmpty is changed as suggested before.) Unfortunately the example is large and takes ages to be reproduced and it took me an age to find that the cause was my change to our version of HughesPJ.hs. Christian the link error shows up as: [...] /usr/bin/ld: ./Logic/Logic.o relocation overflow for relocation entry 5401 in se ction (__TEXT,__text) (displacement too large) collect2: ld returned 1 exit status make: *** [hets] Error 1
participants (2)
-
Christian Maeder
-
Simon Peyton-Jones