@@ -69,8 +69,7 @@ p_funBind
6969 :: Located RdrName
7070 -> MatchGroup GhcPs (LHsExpr GhcPs)
7171 -> R ()
72−p_funBind name mgroup =
73− p_matchGroup (Function name) mgroup
72+p_funBind name = p_matchGroup (Function name)
7473
7574p_matchGroup
7675 :: MatchGroupStyle
@@ -86,11 +85,35 @@ p_matchGroup'
8685 -> MatchGroup GhcPs (Located body)
8786 -> R ()
8887p_matchGroup' placer pretty style MG {..} =
89− sep newline (located' (\m@Match {..} ->
90− p_match' placer pretty style (isInfixMatch m) (matchStrictness m) m_pats m_grhss))
91− (unLoc mg_alts)
88+ sep newline (located' p_Match) (unLoc mg_alts)
89+ where
90+ p_Match m@Match {..} =
91+ p_match'
92+ placer
93+ pretty
94+ (adjustMatchGroupStyle m style)
95+ (isInfixMatch m)
96+ (matchStrictness m)
97+ m_pats
98+ m_grhss
99+ p_Match _ = notImplemented "XMatch"
92100p_matchGroup' _ _ _ (XMatchGroup NoExt) = notImplemented "XMatchGroup"
93101
102+-- | Function id obtained through pattern matching on 'FunBind' should not
103+-- be used to print the actual equations because the different ‘RdrNames’
104+-- used in the equations may have different “decorations” (such as backticks
105+-- and paretheses) associated with them. It is necessary to use per-equation
106+-- names obtained from 'm_ctxt' of 'Match'. This function replaces function
107+-- name inside of 'Function' accordingly.
108+
109+adjustMatchGroupStyle
110+ :: Match GhcPs body
111+ -> MatchGroupStyle
112+ -> MatchGroupStyle
113+adjustMatchGroupStyle m = \case
114+ Function _ -> (Function . mc_fun . m_ctxt) m
115+ style -> style
116+
94117matchStrictness :: Match id body -> SrcStrictness
95118matchStrictness match =
96119 case m_ctxt match of