+
+
+%************************************************************************
+%* *
+\subsection{HsMatchCtxt}
+%* *
+%************************************************************************
+
+\begin{code}
+data HsMatchContext -- Context of a Match or Stmt
+ = ListComp -- List comprehension
+ | DoExpr -- Do Statment
+
+ | FunRhs Name -- Function binding for f
+ | CaseAlt -- Guard on a case alternative
+ | LambdaExpr -- Lambda
+ | PatBindRhs -- Pattern binding
+ | RecUpd -- Record update
+ deriving ()
+
+-- It's convenient to have FunRhs as a Name
+-- throughout so that HsMatchContext doesn't
+-- need to be parameterised.
+-- In the RdrName world we never use the FunRhs variant.
+\end{code}
+
+\begin{code}
+isDoExpr DoExpr = True
+isDoExpr other = False
+
+isDoOrListComp ListComp = True
+isDoOrListComp DoExpr = True
+isDoOrListComp other = False
+\end{code}
+
+\begin{code}
+matchSeparator (FunRhs _) = SLIT("=")
+matchSeparator CaseAlt = SLIT("->")
+matchSeparator LambdaExpr = SLIT("->")
+matchSeparator PatBindRhs = SLIT("=")
+matchSeparator DoExpr = SLIT("<-")
+matchSeparator ListComp = SLIT("<-")
+matchSeparator RecUpd = panic "When is this used?"
+\end{code}
+
+\begin{code}
+pprMatchContext (FunRhs fun) = ptext SLIT("In the definition of") <+> quotes (ppr fun)
+pprMatchContext CaseAlt = ptext SLIT("In a group of case alternatives beginning")
+pprMatchContext RecUpd = ptext SLIT("In a record-update construct")
+pprMatchContext PatBindRhs = ptext SLIT("In a pattern binding")
+pprMatchContext LambdaExpr = ptext SLIT("In a lambda abstraction")
+pprMatchContext DoExpr = ptext SLIT("In a 'do' expression pattern binding")
+pprMatchContext ListComp = ptext SLIT("In a 'list comprension' pattern binding")
+\end{code}