Dhall-haskell: Two identical expressions in a list are formatted differently

Created on 6 Oct 2019  Â·  13Comments  Â·  Source: dhall-lang/dhall-haskell

Dhall version: 1.26.1.

Before formatting:

{ conversation =
    [ { author = "robert", content = [] }
    , { author = "robert", content = [] }
    , { author =
          "bob"
      , content =
          [ text
              ''
              any line going past the 80 characters boundary (e.g. this one is 82)
              ''
          ]
      }
    ]
}

After formatting:

{ conversation =
    [ { author =
          "robert"
      , content = []
      }
    , { author = "robert", content = [] }
    , { author =
          "bob"
      , content =
          [ text
              ''
              any line going past the 80 characters boundary (e.g. this one is 82)
              ''
          ]
      }
    ]
}
bug formatting

All 13 comments

Thanks for the report. I can still reproduce this on master.

I can't reproduce this if I remove the outer record.

Based on the code this seems to be an issue with the prettyprinter package (or at version 1.2.1, which is the version we use to build the release executable). We don't do anything different for each element of the list, but we do let the prettyprinter decide how to format each element of the list. It appears to have decide inconsistently that only one of the two elements needed to be expanded.

I'm going to see if I can minimize this to a example that can reproduce only using prettyprinter code.

I was briefly confused when I noticed that dhall-1.25.0 seemed to handle the example fine, but that's only because function arguments weren't indented before https://github.com/dhall-lang/dhall-haskell/commit/22d46103c185489837f501ab46e9ce57f82f55bc, so the longest line is only 80 characters long.

I've reproduced the problem with all prettyprinter versions >= 1.1.1 since.

Here is a slightly simpler reproducer:

{ x =
    [ [ 0
      , 0
      ]
    , [ 0, 0 ]
    , [ 0
      , 1111111111111111111111111111111111111111111111111111111111111111111111111
      ]
    ]
}

Note that it is always only the first element of the list that is incorrectly formatted over multiple lines.

Even simpler:

g
  [ f
      0
  , f 0
  , f
      111111111111111111111111111111111111111111111111111111111111111111111111111
  ]

Limited to lists and Naturals:

[ [ [ 0
    ]
  , [ 0 ]
  , [ 111111111111111111111111111111111111111111111111111111111111111111111111111
    ]
  ]
]

EDIT: I'll try to extract the relevant code into a reproducer for prettyprinter.

A self-contained reproducer is up here: https://github.com/sjakobi/dhall-issue1400/blob/master/src/Lib.hs

I'll see whether I can reduce it a bit further…

@sjakobi: Nice job minimizing the reproduction! 🙂

I think this formatting in EarnestResearch/dhall-packages is due to the same issue:

1, 2, 3.

The fix for prettyprinter was released in v1.5.0. Now we're just waiting for hnix to make a compatible release.

I believe Prelude.JSON.Tagged should be formatted like this once we use prettyprinter >= 1.5.0:

```
let Tagged
: Type → Type
= λ(a : Type)
→ { field : Text
, nesting :
./Nesting sha256:6284802edd41d5d725aa1ec7687e614e21ad1be7e14dd10996bfa9625105c335
? ./Nesting
, contents : a
}

Was this page helpful?
0 / 5 - 0 ratings