lspitzner / brittany

haskell source code formatter
GNU Affero General Public License v3.0
691 stars 72 forks source link

Single long line when doing pattern matching to extract record fields #268

Open zzantares opened 5 years ago

zzantares commented 5 years ago

Hello, I'm just taking brittany out for a spin for the first time, it's a great work! but one thing I note does not work (I doubt is the desired result) is when doing pattern matching to extract fields from a record, I have enabled NamedFieldPuns extension, and formats like this:

  let
    LongRecordFields { longRecordFieldsOne, longRecordFieldsTwo, longRecordFieldsThree, longRecordFieldsFour, longRecordFieldsFive }
      = longRecordFields

That makes a very long line, I would rather prefer it to be formatted like this:

  let LongRecordFields
        { longRecordFieldsOne
        , longRecordFieldsTwo
        , longRecordFieldsThree
        , longRecordFieldsFour
        , longRecordFieldsFive
        } = longRecordFields

Is this possible to do? If not, what do you think? it could be added or the current behavior is the desired one?

lspitzner commented 5 years ago

Thanks!

I agree, and your preferred formatting looks good to me. We just have not come around to implementing anything in this direction, because patterns can appear in so many different places, and inventing proper layouts for some of them is mildly tricky.

See #143.

But your let example is relatively easy. Might be possible to implement something for let/where, but leaving the more complex contexts of function argument patterns, case, guards (ViewPatterns) etc. for later?

I'll think on this.