#669: negative indentation in Text.PrettyPrint.HughesPJ
------------------------------------------+---------------------------------
Reporter: [EMAIL PROTECTED] | Owner: thorkilnaur
Type: bug | Status: new
Priority: normal | Milestone: 6.10 branch
Component: libraries/pretty | Version: 6.4.1
Severity: minor | Resolution:
Keywords: | Difficulty: Unknown
Testcase: pp1 | Architecture: Unknown
Os: Unknown |
------------------------------------------+---------------------------------
Comment (by benedikt):
To summarize:
If we want to keep the law
"If we compose two layouts a and b using a <g> b, then the layouts of a
and b are preserved"
this bug can be marked as invalid.
Demonstrated on torkil's example
{{{
-- move is the name of the DT constructor Nest (which behaves as
-- if it would move the virtual typewriter's head)
let a = text "a"
let b = nest 4 ( nest 4 ( text "b" ) $$ text "bar" )
a ==> text "a" -->
|a|
b ==> nest 4 (nest 4 (text "b") $$ text "bar")
==> move 8; text "b"; nilabove; move -7; text "bar"; empty -->
|........b|
|....bar|
a <> b ==> text "a"; text "b"; nilabove; move -5; text "bar"; empty
<==> (text "ab" $+$ (nest (-3) $ text bar))
nest 8 (a <> b) -->
|........ab|
|.....bar|
(a <> b) -->
....|ab|
.bar|..|
^ left margin
}}}
So bar has to have a negative indentation of 3, when layouts should be
preserved.
Suppose we want to introduce a combinator <#>, which has a non layout-
preserving semantics.
We would have to agree on a formal semantics.
One possibility would be to say that <#> is as $+$, but the last line of
the first layout and the first line of
the last layout are merged. So this definition of <#> "prepends text to a
layout".
{{{
|a|
<#> (1)
|........b|
|....bar|
|baz.....|
-->
|ab|
|....bar|
|baz....|
------------------
|a|
<#> (2)
|b|
|.c|
-->
|ab|
|.c|
}}}
This could be useful sometimes.
Another possibility would be to state that <#> acts as <>, but ensures
there is no negative indentation.
This definition seems to have hard to predict effects.
{{{
let doc =
|a|
<#> (1)
|........b|
|....bar|
|baz.....|
-->
|ab|
|bar|
|baz|
------------------
nest 4 doc:
|....ab|
|....bar|
|....baz|
}}}
Neither of them seems really convincing to me. Any ideas ?
A usecase for a non-layout preserving combinator would be great too.
best regards, benedikt
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/669#comment:13>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs