[GHC] #1337: Fix wrong indentation from Text.PrettyPrint.HughesPJ fill (fcat and fsep)

GHC trac at galois.com
Sun May 6 16:27:05 EDT 2007


#1337: Fix wrong indentation from Text.PrettyPrint.HughesPJ fill (fcat and fsep)
-----------------------------+----------------------------------------------
  Reporter:  thorkilnaur     |          Owner:  thorkilnaur
      Type:  bug             |         Status:  new        
  Priority:  normal          |      Milestone:             
 Component:  libraries/base  |        Version:  6.6.1      
  Severity:  normal          |       Keywords:             
Difficulty:  Unknown         |             Os:  Unknown    
  Testcase:  pp2             |   Architecture:  Unknown    
-----------------------------+----------------------------------------------
This program:
 {{{
 import Text.PrettyPrint.HughesPJ

 f z doc = renderStyle
             (
               Style {
                 mode = PageMode,
                 lineLength = z,
                 ribbonsPerLine = 1.0
               }
             )
             doc

 l2 = f 6 $ nest 3 $
        fcat [nest 1 $ text "a", nest 2 $ text "b", text "c"]

 main = putStr (l2 ++ "\n")
 }}}
 produces this output:
 {{{
 $ runghc pp2.hs | tr ' ' .
 ....ab
 .c
 $
 }}}
 The expected output is:
 {{{
 ....ab
 ...c
 }}}
 where the {{{c}}} is placed below and 1 position to the left of the
 {{{a}}}.

 As I understand the situation, the problem is that in a {{{fill}}} (used
 by {{{fsep}}} and {{{fcat}}}), the total indentation of all the documents
 placed on one line is used to determine the indentation of the next line
 where only the indentation of the first document should be used. Thus, in
 the example, the {{{c}}} is placed 1+2=3 positions to the left of the
 {{{a}}} which is 2 too many.

 I have attached a patch with a suggested solution. I have also attached a
 patch that adds a suitable test case.

 Note: This problem is also present in GHC's Pretty library and is the
 reason for the bad formatting reported in #1176. Once the present problem
 has been fixed, I intend to go back to #1176 and fix that in a similar
 manner.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1337>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
-------------- next part --------------
_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs at haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


More information about the Glasgow-haskell-bugs mailing list