Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat function application with final list same as final do-block #692

Open
brandon-leapyear opened this issue Mar 13, 2021 · 9 comments
Open
Labels
style Nitpicking and things related to purely visual aspect for formatting.

Comments

@brandon-leapyear
Copy link

Is your feature request related to a problem? Please describe.
In my mind, a final do-block and a long final list should be formatted the same, something like

a1 = x "asdf" $ do
  asdf <- foo
  return asdf

a2 = x "asdf"
  [ foo
  , foo2
  ]

But ormolu currently formats the second one differently from the first (which is already formatted correctly):

a = x "asdf" $ do
  asdf <- foo
  return asdf

a2 =
  x
    "asdf"
    [ foo,
      foo2
    ]

This shows up a lot in tasty tests, where i'd like the format

myTests = testGroup "group1"
  [ testCase "foo" $ do
      foo 1 @?= ...
  ]

but the testGroup format becomes different from the testCase format after ormolu:

myTests =
  testGroup
    "group1"
    [ testCase "foo" $ do
        foo 1 @?= ...
    ]

Describe the solution you'd like
Treat a long final argument the same as a do-block.

Describe alternatives you've considered

Additional context

@mheinzel
Copy link

You might have already considered it, but you can at least avoid the line break between the function arguments using a $ there:

a2 =
  x "asdf" $
    [ foo,
      foo2
    ]

@brandonchinn178
Copy link
Collaborator

hm but wouldnt that violate hlint's redundant $ rule?

@mheinzel
Copy link

Yes, depending on your hlint configuration (I personally usually disable it).

@mrkkrp mrkkrp added the style Nitpicking and things related to purely visual aspect for formatting. label Jun 17, 2021
@brandonchinn178
Copy link
Collaborator

Copied over from fourmolu/fourmolu#46:

Essentially, where an expression is only multiline because it ends with a particular multiline-friendly construct (this is a bit vague, but definitely includes record update and construction. case and \case statements, multi-way-if, and probably list literals), I'd like to format the preceding part of the expression in single-line style.
As an extreme case, we currently turn:

f = g 1 2 3 4 5 R
    { a = ()
    , b = ()
    }

in to:

f =
    g
        1
        2
        3
        4
        5
        R
            { a = ()
            , b = ()
            }

while the above example is exacerbated by configuring Fourmolu to use 4-space indentation, it's still an issue in plain Ormolu:

f =
  g
    1
    2
    3
    4
    5
    R
      { a = (),
        b = ()
      }

when I think it would be better if Ormolu could do

f =
  g 1 2 3 4 5 R
    { a = (),
      b = ()
    }

or even

f =
  g 1 2 3 4 5
    R
      { a = (),
        b = ()
      }

(which you could get with a $ before R, as mentioned by @mheinzel above, but hlint complains about unnecessary $)

@brandonchinn178

This comment was marked as off-topic.

@amesgen

This comment was marked as off-topic.

@brandonchinn178

This comment was marked as off-topic.

@brandonchinn178
Copy link
Collaborator

@mrkkrp Any comments on this? If a PR were submitted for this, would it be accepted?

Fourmolu might start moving on this if Ormolu isn't interested, but it'd be really great to avoid the divergence if possible

@mrkkrp
Copy link
Member

mrkkrp commented Oct 3, 2023

@brandonchinn178 I don't really see a good reason to introduce an exception for how a multiline function application is formatted in this case. I'd value consistency more even when a list is involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
style Nitpicking and things related to purely visual aspect for formatting.
Projects
None yet
Development

No branches or pull requests

5 participants