Closed torgeirsh closed 5 years ago
Yes we know, this will be implemented better in future. Duplicate of #315, which see.
Is it necessary to consider operator precedence? Couldn't it preserve the original grouping?
Precedence determines the grouping. GHC first parses everything as if all operators have the same precedence and the same fixity. This way things on the same line end up not grouped together but as parts of different nested expressions so the span information we infer tells Ormolu that the current layout is multi-line, so you get every operator on its own line. Long story short, yes, we need to infer relative precedence (not necessarily exact precedence though) to preserve the way operators are grouped.
I've been experimenting with Ormolu, and came across some bad formatting for Aeson code. Consider the following parser:
Ormolu transforms it into:
I think it's harder to see the purpose of the code at a glance.