-rnNormalStmts ctxt (L loc (ExprStmt expr _) : stmts)
- = rnLExpr expr `thenM` \ (expr', fv_expr) ->
- rnNormalStmts ctxt stmts `thenM` \ (stmts', fvs) ->
- returnM (L loc (ExprStmt expr' placeHolderType) : stmts',
- fv_expr `plusFV` fvs)
-
-rnNormalStmts ctxt [L loc (ResultStmt expr)]
- = rnLExpr expr `thenM` \ (expr', fv_expr) ->
- returnM ([L loc (ResultStmt expr')], fv_expr)
-
-rnNormalStmts ctxt (L loc (BindStmt pat expr) : stmts)
- = rnLExpr expr `thenM` \ (expr', fv_expr) ->
- -- The binders do not scope over the expression
-
- let
- reportUnused =
- case ctxt of
- ParStmtCtxt{} -> False
- _ -> True
- in
- rnPatsAndThen (StmtCtxt ctxt) reportUnused [pat] $ \ [pat'] ->
- rnNormalStmts ctxt stmts `thenM` \ (stmts', fvs) ->
- returnM (L loc (BindStmt pat' expr') : stmts',
- fv_expr `plusFV` fvs) -- fv_expr shouldn't really be filtered by
- -- the rnPatsAndThen, but it does not matter
-
-rnNormalStmts ctxt (L loc (LetStmt binds) : stmts)
- = checkErr (ok ctxt binds) (badIpBinds binds) `thenM_`
- rnBindGroupsAndThen binds ( \ binds' ->
- rnNormalStmts ctxt stmts `thenM` \ (stmts', fvs) ->
- returnM (L loc (LetStmt binds') : stmts', fvs))
+rnNormalStmts ctxt (L loc stmt : stmts) thing_inside
+ = do { ((stmt', (stmts', thing)), fvs)
+ <- rnStmt ctxt stmt $
+ rnNormalStmts ctxt stmts thing_inside
+ ; return (((L loc stmt' : stmts'), thing), fvs) }
+
+rnStmt :: HsStmtContext Name -> Stmt RdrName
+ -> RnM (thing, FreeVars)
+ -> RnM ((Stmt Name, thing), FreeVars)
+
+rnStmt ctxt (ExprStmt expr _ _) thing_inside
+ = do { (expr', fv_expr) <- rnLExpr expr
+ ; (then_op, fvs1) <- lookupSyntaxName thenMName
+ ; (thing, fvs2) <- thing_inside
+ ; return ((ExprStmt expr' then_op placeHolderType, thing),
+ fv_expr `plusFV` fvs1 `plusFV` fvs2) }
+
+rnStmt ctxt (BindStmt pat expr _ _) thing_inside
+ = do { (expr', fv_expr) <- rnLExpr expr
+ -- The binders do not scope over the expression
+ ; (bind_op, fvs1) <- lookupSyntaxName bindMName
+ ; (fail_op, fvs2) <- lookupSyntaxName failMName
+
+ ; let reportUnused = case ctxt of
+ ParStmtCtxt{} -> False
+ _ -> True
+ ; rnPatsAndThen (StmtCtxt ctxt) reportUnused [pat] $ \ [pat'] -> do
+ { (thing, fvs3) <- thing_inside
+ ; return ((BindStmt pat' expr' bind_op fail_op, thing),
+ fv_expr `plusFV` fvs1 `plusFV` fvs2 `plusFV` fvs3) }}
+ -- fv_expr shouldn't really be filtered by
+ -- the rnPatsAndThen, but it does not matter
+
+rnStmt ctxt (LetStmt binds) thing_inside
+ = do { checkErr (ok ctxt binds) (badIpBinds binds)
+ ; rnBindGroupsAndThen binds $ \ binds' -> do
+ { (thing, fvs) <- thing_inside
+ ; return ((LetStmt binds', thing), fvs) }}