Closed brandonchinn178 closed 1 year ago
Note that <|>
is not in the Prelude
, so you e.g. import Control.Applicative
to make Ormolu aware of its fixity. If you do not do that, Ormolu assumes that <|>
has the default fixity infixl 9
, which explains the outputs you posted in this issue.
With that import, Ormolu formats your two inputs like this:
Input | Output |
---|---|
```haskell import Control.Applicative foo = 1 <$ bar1 <|> 2 <$ bar2 <|> 3 <$ bar3 foo = 1 <$ bar1 <|> 2 <$ bar2 <|> 3 <$ bar3 ``` | ```haskell import Control.Applicative foo = 1 <$ bar1 <|> 2 <$ bar2 <|> 3 <$ bar3 foo = 1 <$ bar1 <|> 2 <$ bar2 <|> 3 <$ bar3 ``` |
Now, I think the first foo
is formatted just as you expected. The second foo
is formatted like this due to following principle from the README:
This means that the choices between single-line/multi-line layouts in certain situations are made by the user, not by an algorithm.
When we insert the implicit parentheses explicitly for the second foo
, we get
foo =
(1
<$ bar1) <|> (2
<$ bar2) <|> (3
<$ bar3)
Ormolu now sees that all of the three occurrences of x <$ barx
are multi-line, so it respects that choice in the output.
Hope that answers the question!
🤦♂️ once again, a stupid mistake for the world to see. Sorry about that, thanks a ton!
For the following input code:
Ormolu formats it as
Since
<$
binds more tightly than<|>
, this seems like odd formatting. Indeed, Ormolu thinks this is the correct format:Is this intended behavior?
For reference: