Re: possible bug in pretty-1.0.1.0

John MacFarlane schrieb:
I noticed a difference in how "hang" works between pretty-1.0.0.0 and pretty-1.0.1.0. I think it's a bug. If this isn't the right place to report it, please let me know where I should. (Maintainer is listed as libraries@haskell.org, but that is a closed mailing list. Perhaps Cabal should include a report-bugs-at field?)
John
GHCi, version 6.8.3: http://www.haskell.org/ghc/ :? for help ... Prelude Text.PrettyPrint> putStrLn $ render $ hang (char '*') 4 (text "hi" $$ text "there") Loading package pretty-1.0.0.0 ... linking ... done. * hi there
GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help ... Prelude Text.PrettyPrint> putStrLn $ render $ hang (char '*') 4 (text "hi" $$ text "there") Loading package pretty-1.0.1.0 ... linking ... done. * hi there Hi John,
I think you're right, from the perspective of 'hang' the last set of patches (http://hackage.haskell.org/trac/ghc/ticket/2393) indeed introduced a bug. Unfortunately a good description of what hang is _intended_ to mean is still missing in the documentation, but I'll assume that
hang (text "*") 4 (sep [ text "hi", text "there" ])
should either layout as
* hi there
or
* hi there
If only the second layout is of interest (like in your example), then
hang' d1 n d2 = d1 $$ (nest n d2)
should do the job. Related issue, we changed vcat to mean (foldr $+$ empty) instead of (foldr $$ empty) - either revert this change or update the documentation ? [1] Unfortunately, the situations is a bit trickier for hang (i.e. for sep[A, nest n B]); allowing overlap violates Invariant 7: The first line of the first layout has to be longer than the first line of the second layout because
sep [A, nest n B] ~ oneLiner (A <+> B) `union` A $$ (nest n B) with e.g. [A="a",B="b",n="4"] "a b" `union` "a b"
which causes the pretty printer to select an even longer! line if (A <+> B) doesn't fit on one line. I'm not sure how to resolve this - should sep [A, B] really overlap A and B if they do not fit on a line ??? Still, if it seems to be the right thing to do, it is easy to allow overlap in sep/cat. Otherwise hang might need to be changed. best regards, benedikt [1] Either hunk ./Text/PrettyPrint/HughesPJ.hs 114 - vcat is a list version of $$ + vcat is a list version of $+$ hunk ./Text/PrettyPrint/HughesPJ.hs 316 -vcat :: [Doc] -> Doc; -- ^List version of '$$'. +vcat :: [Doc] -> Doc; -- ^List version of '$+$'. or hunk ./Text/PrettyPrint/HughesPJ.hs 497 -vcat = reduceAB . foldr (above_' True) empty +vcat = reduceAB . foldr (above_' False) empty because of 505: above_' g p q = Above p g q 536: | Above Doc Bool Doc -- True <=> never overlap
participants (1)
-
Benedikt Huber