+%************************************************************************
+%* *
+%* matchGuard : make a MatchResult from a guarded RHS *
+%* *
+%************************************************************************
+
+\begin{code}
+matchGuard :: [TypecheckedStmt] -- Guard
+ -> DsMatchContext -- Context
+ -> DsM MatchResult
+
+matchGuard (ExprStmt expr locn : should_be_null) ctx
+ = putSrcLocDs locn (dsExpr expr) `thenDs` \ core_expr ->
+ returnDs (cantFailMatchResult core_expr)
+
+ -- Turn an "otherwise" guard is a no-op
+matchGuard (GuardStmt (HsVar v) _ : stmts) ctx
+ | uniq == otherwiseIdKey
+ || uniq == trueDataConKey
+ = matchGuard stmts ctx
+ where
+ uniq = getUnique v
+
+matchGuard (GuardStmt expr locn : stmts) ctx
+ = matchGuard stmts ctx `thenDs` \ match_result ->
+ putSrcLocDs locn (dsExpr expr) `thenDs` \ pred_expr ->
+ returnDs (mkGuardedMatchResult pred_expr match_result)
+
+matchGuard (LetStmt binds : stmts) ctx
+ = matchGuard stmts ctx `thenDs` \ match_result ->
+ returnDs (adjustMatchResultDs (dsLet binds) match_result)
+ -- NB the dsLet occurs inside the match_result
+
+matchGuard (BindStmt pat rhs locn : stmts) ctx
+ = matchGuard stmts ctx `thenDs` \ match_result ->
+ putSrcLocDs locn (dsExpr rhs) `thenDs` \ core_rhs ->
+ matchSinglePat core_rhs ctx pat match_result
+\end{code}
+
+Should {\em fail} if @e@ returns @D@
+\begin{verbatim}
+f x | p <- e', let C y# = e, f y# = r1
+ | otherwise = r2
+\end{verbatim}
\ No newline at end of file