@@ -31,8 +31,8 @@ data MatchGroupStyle
3131 | LambdaCase
3232
3333data GroupStyle
34− = Guard
35− | MultiIf
34+ = EqualSign
35+ | RightArrow
3636
3737-- | Expression placement. This marks the places where expressions that
3838-- implement handing forms may use them.
@@ -111,16 +111,24 @@ p_match style m_pats m_grhss = do
111111 return inci'
112112 inci' $ do
113113 let GRHSs {..} = m_grhss
114+ hasGuards = withGuards grhssGRHSs
114115 unless (length grhssGRHSs > 1) $ do
115− space
116− txt $ case style of
117− Function _ -> "="
118− PatternBind -> "="
119− _ -> "->"
116+ case style of
117+ Function _ -> txt " ="
118+ PatternBind -> txt " ="
119+ Case -> unless hasGuards (txt " ->")
120+ _ -> txt " ->"
120121 let combinedSpans = combineSrcSpans' $
121122 getGRHSSpan . unL <$> NE.fromList grhssGRHSs
122123 p_body = do
123− newlineSep (located' (p_grhs Guard)) grhssGRHSs
124+ let groupStyle =
125+ case style of
126+ Case ->
127+ if hasGuards
128+ then RightArrow
129+ else EqualSign
130+ _ -> EqualSign
131+ newlineSep (located' (p_grhs groupStyle)) grhssGRHSs
124132 unless (GHC.isEmptyLocalBindsPR (unL grhssLocalBinds)) $ do
125133 newline
126134 line (txt "where")
@@ -141,8 +149,8 @@ p_grhs style (GRHS NoExt guards body) =
141149 velt $ withSep comma (located' p_stmt) xs
142150 space
143151 txt $ case style of
144− Guard -> "="
145− MultiIf -> "->"
152+ EqualSign -> "="
153+ RightArrow -> "->"
146154 breakpoint
147155 inci p_body
148156 where
@@ -289,15 +297,17 @@ p_hsExpr = \case
289297 located if' p_hsExpr
290298 breakpoint
291299 txt "then"
292− located then' $ \x ->
293− placeHanging (exprPlacement x) (p_hsExpr x)
300+ located then' $ \x -> do
301+ breakpoint
302+ inci (p_hsExpr x)
294303 breakpoint
295304 txt "else"
296− located else' $ \x ->
297− placeHanging (exprPlacement x) (p_hsExpr x)
305+ located else' $ \x -> do
306+ breakpoint
307+ inci (p_hsExpr x)
298308 HsMultiIf NoExt guards -> do
299309 txt "if "
300− sitcc $ newlineSep (located' (p_grhs MultiIf)) guards
310+ sitcc $ newlineSep (located' (p_grhs RightArrow)) guards
301311 HsLet NoExt localBinds e -> do
302312 txt "let "
303313 sitcc (located localBinds p_hsLocalBinds)
@@ -539,3 +549,10 @@ exprPlacement = \case
539549 HsDo NoExt _ _ -> Hanging
540550 HsLamCase NoExt _ -> Hanging
541551 _ -> Normal
552+
553+withGuards :: [LGRHS GhcPs (LHsExpr GhcPs)] -> Bool
554+withGuards = any (checkOne . unL)
555+ where
556+ checkOne :: GRHS GhcPs (LHsExpr GhcPs) -> Bool
557+ checkOne (GRHS NoExt [] _) = False
558+ checkOne _ = True