Undesirable formatting for infix operators and comments #111

Closed
opened 2018-01-17 16:56:29 +01:00 by matthew-piziak · 1 comment
matthew-piziak commented 2018-01-17 16:56:29 +01:00 (Migrated from github.com)

In this example, the inline comments describe the lines that they are on.

alternatives :: Parser (Maybe Text)
alternatives =
      alternativeOne   -- first try this one
  <|> alterantiveTwo   -- then this one
  <|> alternativeThree -- then this one
  where
    alternativeOne   = purer "one"
    alternativeTwo   = purer "two"
    alterantiveThree = purer "three"

Unfortunately this gets formatted as this:

alternatives :: Parser (Maybe Text)
alternatives = alternativeOne   -- first try this one
                              <|> alterantiveTwo   -- then this one
                                                 <|> alternativeThree --  then this one
 where
  alternativeOne   = purer "one"
  alternativeTwo   = purer "two"
  alterantiveThree = purer "three"

Seems a bit aggressive.

In this example, the inline comments describe the lines that they are on. ``` alternatives :: Parser (Maybe Text) alternatives = alternativeOne -- first try this one <|> alterantiveTwo -- then this one <|> alternativeThree -- then this one where alternativeOne = purer "one" alternativeTwo = purer "two" alterantiveThree = purer "three" ``` Unfortunately this gets formatted as this: ``` alternatives :: Parser (Maybe Text) alternatives = alternativeOne -- first try this one <|> alterantiveTwo -- then this one <|> alternativeThree -- then this one where alternativeOne = purer "one" alternativeTwo = purer "two" alterantiveThree = purer "three" ``` Seems a bit aggressive.
lspitzner commented 2018-03-23 17:06:54 +01:00 (Migrated from github.com)

This gives

alternatives :: Parser (Maybe Text)
alternatives =
  alternativeOne   -- first try this one
    <|> alterantiveTwo   -- then this one
    <|> alternativeThree -- then this one
 where
  alternativeOne   = purer "one"
  alternativeTwo   = purer "two"
  alterantiveThree = purer "three"

now. Not sure if we want the alignment of the alternatives in general, but if desired there is at least the trick of using parens:

alternatives =
  (   alternativeOne   -- first try this one
  <|> alterantiveTwo   -- then this one
  <|> alternativeThree -- then this one
  )

(which of course directly runs into some comment-getting-moved bug. One sec.)

This gives ~~~~.hs alternatives :: Parser (Maybe Text) alternatives = alternativeOne -- first try this one <|> alterantiveTwo -- then this one <|> alternativeThree -- then this one where alternativeOne = purer "one" alternativeTwo = purer "two" alterantiveThree = purer "three" ~~~~ now. Not sure if we want the alignment of the alternatives in general, but if desired there is at least the trick of using parens: ~~~~.hs alternatives = ( alternativeOne -- first try this one <|> alterantiveTwo -- then this one <|> alternativeThree -- then this one ) ~~~~ (which of course directly runs into some comment-getting-moved bug. One sec.)
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: hexagoxel/brittany#111
There is no content yet.