List in last line of do-block prevents formatting #296

Open
opened 2020-04-16 12:10:55 +02:00 by gutjuri · 1 comment
gutjuri commented 2020-04-16 12:10:55 +02:00 (Migrated from github.com)

I have the following function:

wnums :: [Double] -> [Double]
wnums nums = do
  a  <- nums
  b  <- nums \\ [a]
  c  <- nums \\ [a, b]
  d  <- nums \\ [a, b, c]
  o1 <- opts
  o2 <- opts
  o3 <- opts
  [   (a `o1` b) `o2` (c `o3` d)
    , ((a `o1` b) `o2` c) `o3` d
    , a `o1` (b `o2` (c `o3` d))
    , (a `o1` (b `o2` c)) `o3` d
    , a `o1` ((b `o2` c) `o3` d)
    ]

This function compiles but when i run brittany on the source file then it errors out with ERROR: brittany pretty printer returned syntactically invalid result.

Without this function the source file can be reformatted just fine.

I have the following function: ```haskell wnums :: [Double] -> [Double] wnums nums = do a <- nums b <- nums \\ [a] c <- nums \\ [a, b] d <- nums \\ [a, b, c] o1 <- opts o2 <- opts o3 <- opts [ (a `o1` b) `o2` (c `o3` d) , ((a `o1` b) `o2` c) `o3` d , a `o1` (b `o2` (c `o3` d)) , (a `o1` (b `o2` c)) `o3` d , a `o1` ((b `o2` c) `o3` d) ] ``` This function compiles but when i run brittany on the source file then it errors out with `ERROR: brittany pretty printer returned syntactically invalid result.` Without this function the source file can be reformatted just fine.
tfausak commented 2020-04-16 13:36:08 +02:00 (Migrated from github.com)

Sounds related to #290, in that formatting things in do notation is different that regular code. Here's what Brittany 0.12.1.1 outputs (using --output-on-errors):

ERROR: brittany pretty printer returned syntactically invalid result.
wnums :: [Double] -> [Double]
wnums nums = do
  a  <- nums
  b  <- nums \\ [a]
  c  <- nums \\ [a, b]
  d  <- nums \\ [a, b, c]
  o1 <- opts
  o2 <- opts
  o3 <- opts
  [ (a `o1` b) `o2` (c `o3` d)
  , ((a `o1` b) `o2` c) `o3` d
  , a `o1` (b `o2` (c `o3` d))
  , (a `o1` (b `o2` c)) `o3` d
  , a `o1` ((b `o2` c) `o3` d)
  ]

As a workaround, you can pass the list to a function like id. Or you can explicitly build the list using (:).

Sounds related to #290, in that formatting things in `do` notation is different that regular code. Here's what Brittany 0.12.1.1 outputs (using `--output-on-errors`): ``` hs ERROR: brittany pretty printer returned syntactically invalid result. wnums :: [Double] -> [Double] wnums nums = do a <- nums b <- nums \\ [a] c <- nums \\ [a, b] d <- nums \\ [a, b, c] o1 <- opts o2 <- opts o3 <- opts [ (a `o1` b) `o2` (c `o3` d) , ((a `o1` b) `o2` c) `o3` d , a `o1` (b `o2` (c `o3` d)) , (a `o1` (b `o2` c)) `o3` d , a `o1` ((b `o2` c) `o3` d) ] ``` As a workaround, you can pass the list to a function like `id`. Or you can explicitly build the list using `(:)`.
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#296
There is no content yet.