@@ -31,8 +31,8 @@ data MatchGroupStyle
31 | LambdaCase
31 | LambdaCase
33data GroupStyle
33data GroupStyle
34− = Guard
34+ = EqualSign
35− | MultiIf
35+ | RightArrow
37-- | Expression placement. This marks the places where expressions that
37-- | Expression placement. This marks the places where expressions that
38-- implement handing forms may use them.
38-- implement handing forms may use them.
@@ -111,16 +111,24 @@ p_match style m_pats m_grhss = do
111 return inci'
111 return inci'
112 inci' $ do
112 inci' $ do
113 let GRHSs {..} = m_grhss
113 let GRHSs {..} = m_grhss
114+ hasGuards = withGuards grhssGRHSs
114 unless (length grhssGRHSs > 1) $ do
115 unless (length grhssGRHSs > 1) $ do
116− txt $ case style of
116+ case style of
117− Function _ -> "="
117+ Function _ -> txt " ="
118− PatternBind -> "="
118+ PatternBind -> txt " ="
119+ Case -> unless hasGuards (txt " ->")
119− _ -> "->"
120+ _ -> txt " ->"
120 let combinedSpans = combineSrcSpans' $
121 let combinedSpans = combineSrcSpans' $
121 getGRHSSpan . unL <$> NE.fromList grhssGRHSs
122 getGRHSSpan . unL <$> NE.fromList grhssGRHSs
122 p_body = do
123 p_body = do
123− newlineSep (located' (p_grhs Guard)) grhssGRHSs
131+ newlineSep (located' (p_grhs groupStyle)) grhssGRHSs
124 unless (GHC.isEmptyLocalBindsPR (unL grhssLocalBinds)) $ do
132 unless (GHC.isEmptyLocalBindsPR (unL grhssLocalBinds)) $ do
126 line (txt "where")
134 line (txt "where")
@@ -141,8 +149,8 @@ p_grhs style (GRHS NoExt guards body) =
141 velt $ withSep comma (located' p_stmt) xs
149 velt $ withSep comma (located' p_stmt) xs
143 txt $ case style of
151 txt $ case style of
144− Guard -> "="
152+ EqualSign -> "="
145− MultiIf -> "->"
153+ RightArrow -> "->"
146 breakpoint
154 breakpoint
147 inci p_body
155 inci p_body
@@ -289,15 +297,17 @@ p_hsExpr = \case
289 located if' p_hsExpr
297 located if' p_hsExpr
290 breakpoint
298 breakpoint
291 txt "then"
299 txt "then"
292− located then' $ \x ->
300+ located then' $ \x -> do
293− placeHanging (exprPlacement x) (p_hsExpr x)
301+ breakpoint
294 breakpoint
303 breakpoint
295 txt "else"
304 txt "else"
296− located else' $ \x ->
305+ located else' $ \x -> do
297− placeHanging (exprPlacement x) (p_hsExpr x)
306+ breakpoint
298 HsMultiIf NoExt guards -> do
308 HsMultiIf NoExt guards -> do
299 txt "if "
309 txt "if "
300− sitcc $ newlineSep (located' (p_grhs MultiIf)) guards
310+ sitcc $ newlineSep (located' (p_grhs RightArrow)) guards
301 HsLet NoExt localBinds e -> do
311 HsLet NoExt localBinds e -> do
302 txt "let "
312 txt "let "
303 sitcc (located localBinds p_hsLocalBinds)
313 sitcc (located localBinds p_hsLocalBinds)
@@ -539,3 +549,10 @@ exprPlacement = \case
539 HsDo NoExt _ _ -> Hanging
549 HsDo NoExt _ _ -> Hanging
540 HsLamCase NoExt _ -> Hanging
550 HsLamCase NoExt _ -> Hanging
541 _ -> Normal
551 _ -> Normal
553+withGuards :: [LGRHS GhcPs (LHsExpr GhcPs)] -> Bool
554+withGuards = any (checkOne . unL)
556+ checkOne :: GRHS GhcPs (LHsExpr GhcPs) -> Bool
557+ checkOne (GRHS NoExt [] _) = False