Given consecutive indented (ie. non-top-level) let blocks, dhall-format inserts trailing whitespace.
Example:
let foo = 1
in λ(bar : Integer)
→ let exposePort =
λ(portSpec : { ext : Integer, int : Integer })
→ Integer/show portSpec.ext ++ ":" ++ Integer/show portSpec.int
in let exposeSamePort =
λ(port : Integer) → exposePort { ext = port, int = port }
in { blah = bar }
Here, whitespace is inserted on the empty lines above the last two lines which begin with in.
I don't know a good way to fix that within dhall. dhall uses the prettyprinter library and the align function used to indent the lambda expression is what is generating that leading whitespace. You might try opening an issue against the prettyprinter library to see if there is a way it can not emit whitespace for empty lines
Thanks. I've filed an issue upstream for discussion.
Upstream have closed that issue:
I’m closing this as »won’t fix« – a separate pass over the generated SimpleDoc can be used to achieve the desired functionality, but at the cost of, well, another pass over the SimpleDoc. The precise semantics of what trimming whitespace means depend too much on the way annotations are used in each specific case, so I don’t see how to implement a general function that works well for all use cases.
Not really clear if this provides a way forward, but given a pointer, I could take a look.
@purcell: This might still be fixable if you post-process the pretty-printed Text to strip trailing white-space within dhall-format
Yeah, I wondered if that would need special handling for multi-line strings.
Oh yeah, good point. This might not be as straightforward after all
As noted in https://github.com/quchen/prettyprinter/issues/46#issuecomment-388653335:
…in Dhall's pretty-printer logic that causes it to emit a whitespace after imports.
For example:
$ cat test.dhall
{ foo = ./bar.dhall, qux = "12345678901234567890123456789012345678901234567890" } : ./baz.dhall
$ <test.dhall dhall-format
{ foo =
./bar.dhall
, qux =
"12345678901234567890123456789012345678901234567890"
}
: ./baz.dhall
$ <test.dhall dhall-format | tr ' ' '␣'
␣␣{␣foo␣=
␣␣␣␣␣␣./bar.dhall␣
␣␣,␣qux␣=
␣␣␣␣␣␣"12345678901234567890123456789012345678901234567890"
␣␣}
:␣./baz.dhall␣
$ dhall-format --version
1.11.1
FWIW, prettyprinter supports trimming trailing whitespace as of yesterday, https://github.com/quchen/prettyprinter/commit/46626c0e74f9f8cb792d816ca7a28921430e4f20, released as prettyprinter 1.2.1.
@quchen I gave this ago but it seems to also strip empty lines entirely.
Without removeTrailingWhitespace:
let foo = 1
in λ(bar : Integer)
→ let exposePort =
λ(portSpec : { ext : Integer, int : Integer })
→ Integer/show portSpec.ext ++ ":" ++ Integer/show portSpec.int
in let exposeSamePort =
λ(port : Integer) → exposePort { ext = port, int = port }
in { blah = bar }
With removeTrailingWhitespace:
let foo = 1
in λ(bar : Integer)
→ let exposePort =
λ(portSpec : { ext : Integer, int : Integer })
→ Integer/show portSpec.ext ++ ":" ++ Integer/show portSpec.int
in let exposeSamePort =
λ(port : Integer) → exposePort { ext = port, int = port }
in { blah = bar }
I just fixed the whitespace-empty-line issue I think, https://github.com/quchen/prettyprinter/issues/71. Do you think you could try it out before I build a release? You seem to have quite the extensive use case testsuite.
Certainly, I'll try and give this a try when I'm home later. Thanks for the fix!
@quchen I can confirm that your commit works, thanks!
Most helpful comment
FWIW,
prettyprintersupports trimming trailing whitespace as of yesterday, https://github.com/quchen/prettyprinter/commit/46626c0e74f9f8cb792d816ca7a28921430e4f20, released as prettyprinter 1.2.1.