@@ -15,12 +15,12 @@ import Data.List (sortOn)
1515import GHC
1616import Ormolu.Printer.Combinators
1717import Ormolu.Printer.Meat.Common
18−import Ormolu.Printer.Meat.Type
1918import Ormolu.Printer.Meat.Declaration.Pat
2019import Ormolu.Printer.Meat.Declaration.Signature
20+import Ormolu.Printer.Meat.Type
2121import Ormolu.Utils
22−import SrcLoc (isOneLineSpan)
2322import Outputable (Outputable (..))
23+import SrcLoc (isOneLineSpan)
2424import qualified Data.List.NonEmpty as NE
2525
2626p_valDecl :: HsBindLR GhcPs GhcPs -> R ()
@@ -111,14 +111,14 @@ p_match style m_pats m_grhss = do
111111 case style of
112112 Lambda -> return ()
113113 _ -> breakpoint
114− newlineSep (located' (p_grhs Pattern)) grhssGRHSs
114+ newlineSep (located' (p_grhs Guard)) grhssGRHSs
115115 unless (GHC.isEmptyLocalBindsPR (unL grhssLocalBinds)) $ do
116116 newline
117117 line (txt "where")
118118 inci (located grhssLocalBinds p_hsLocalBinds)
119119
120120data GroupStyle
121− = Pattern
121+ = Guard
122122 | MultiIf
123123
124124p_grhs :: GroupStyle -> GRHS GhcPs (LHsExpr GhcPs) -> R ()
@@ -130,7 +130,7 @@ p_grhs style (GRHS NoExt guards body) =
130130 velt $ withSep comma (located' p_stmt) xs
131131 space
132132 txt $ case style of
133− Pattern -> "="
133+ Guard -> "="
134134 MultiIf -> "->"
135135 breakpoint
136136 inci p_body
@@ -234,17 +234,32 @@ p_hsExpr = \case
234234 breakpoint
235235 inci (located x p_hsExpr)
236236 ExplicitTuple NoExt args boxity -> do
237+ let isSection = any (isMissing . unL) args
238+ isMissing = \case
239+ Missing NoExt -> True
240+ _ -> False
237241 let parens' =
238242 case boxity of
239243 Boxed -> parens
240244 Unboxed -> parensHash
241− parens' $ velt (withSep comma (located' p_hsTupArg) args)
242− ExplicitSum NoExt tag arity x -> do
245+ parens' $ if isSection
246+ then sequence_ (withSep (txt ",") (located' p_hsTupArg) args)
247+ else velt (withSep comma (located' p_hsTupArg) args)
248+ ExplicitSum NoExt tag arity e -> do
243249 let before = tag - 1
244250 after = arity - before - 1
245− args = replicate before Nothing <> [Just x] <> replicate after Nothing
246− parensHash $
247− velt (withSep (txt "| ") (maybe (pure ()) (located' p_hsExpr)) args)
251+ args = replicate before Nothing <> [Just e] <> replicate after Nothing
252+ f (x,i) = do
253+ let isFirst = i == 0
254+ isLast = i == arity - 1
255+ case x of
256+ Nothing ->
257+ unless (isFirst || isLast) space
258+ Just l -> do
259+ unless isFirst space
260+ located l p_hsExpr
261+ unless isLast space
262+ parensHash $ sequence_ (withSep (txt "|") f (zip args [0..]))
248263 HsCase NoExt e mgroup -> do
249264 txt "case "
250265 located e p_hsExpr
@@ -265,10 +280,8 @@ p_hsExpr = \case
265280 breakpoint
266281 inci (p_hsExpr x)
267282 HsMultiIf NoExt guards -> do
268− txt "if"
269− inci $ forM_ guards $ \g -> do
270− breakpoint
271− located g (p_grhs MultiIf)
283+ txt "if "
284+ sitcc $ newlineSep (located' (p_grhs MultiIf)) guards
272285 HsLet NoExt localBinds e -> do
273286 txt "let "
274287 sitcc (located localBinds p_hsLocalBinds)
@@ -300,24 +313,25 @@ p_hsExpr = \case
300313 let HsWC {..} = affix
301314 HsIB {..} = hswc_body
302315 located hsib_body p_hsType
303− ArithSeq NoExt _ x ->
316+ ArithSeq NoExt _ x -> do
317+ let breakpoint' = vlayout (return ()) newline
304318 case x of
305319 From from -> brackets $ do
306320 located from p_hsExpr
307− breakpoint
321+ breakpoint'
308322 txt ".."
309323 FromThen from next -> brackets $ do
310324 velt (withSep comma (located' p_hsExpr) [from, next])
311− breakpoint
325+ breakpoint'
312326 txt ".."
313327 FromTo from to -> brackets $ do
314328 located from p_hsExpr
315− breakpoint
329+ breakpoint'
316330 txt ".. "
317331 located to p_hsExpr
318332 FromThenTo from next to -> brackets $ do
319333 velt (withSep comma (located' p_hsExpr) [from, next])
320− breakpoint
334+ breakpoint'
321335 txt ".. "
322336 located to p_hsExpr
323337 HsSCC NoExt _ name x -> do