tweag / ormolu

A formatter for Haskell source code
https://ormolu-live.tweag.io
Other
958 stars 83 forks source link

linebreaks in declarations / do-notation #361

Closed argantos closed 5 years ago

argantos commented 5 years ago

consider

test = several . functions . which . soALinebreakIsAppropriate
  . veryLongFunctionName

ormolu output:

test =
  several . functions . which . soALinebreakIsAppropriate
    . veryLongFunctionName

same thing happens with test <- ...

the newline after the = / <- seems to be wasted IMHO. maybe ormolu could respect the user's choice whether or not to put a newline after = / <-?

mrkkrp commented 5 years ago

Only a few constructions that have "hanging form" such as do-blocks can be placed immediately after = when body is multi-line. I think when we had this discussion the conclusion was that it helps readability and looking at your examples, I think that indeed the second version is more readable. I'm not sure what "wasted" means in this case.

argantos commented 5 years ago

Yeah, readability is subjective. Here another example:

-- ormolu output
readConfig = do
  confPath <-
    getArgs >>= \case
      p : _ -> pure p
      _ -> fail "expected path to config file"
  D.inputFile D.auto confPath

vs

readConfig = do
  confPath <- getArgs >>= \case
    p : _ -> pure p
    _ -> fail "expected path to config file"
  D.inputFile D.auto confPath

I like the second option as it is "terser"; IMHO the linebreak does not help in any way.

My point is that ormolu could try to preserve the user's choice whether they want linebreaks after =/<- – for me, that it is in line with respecting single-line/multi-line layouts.

But the whole thing is ofc only a minor issue. I'd also create a PR if that simplifies things (might take some time).

mrkkrp commented 5 years ago

Regarding your last comment, I believe #399 fixed that, now expressions can hang on the right-hand side of <- in do-blocks. I'm going to close this one.