X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2FdeSugar%2FDsExpr.lhs;h=4088e44b1b9504fca5b240691670e466d87b61a0;hp=c55c2d4c748e6aef9670e704b579059b25f48209;hb=f6d254cccd3dc25fff9ff50c2e1bea52b10345e4;hpb=4ac2bb39dffb4b825ece73b349ff0d56d79092d7 diff --git a/compiler/deSugar/DsExpr.lhs b/compiler/deSugar/DsExpr.lhs index c55c2d4..4088e44 100644 --- a/compiler/deSugar/DsExpr.lhs +++ b/compiler/deSugar/DsExpr.lhs @@ -327,10 +327,10 @@ dsExpr (HsLet binds body) = do -- dsExpr (HsDo ListComp stmts res_ty) = dsListComp stmts res_ty dsExpr (HsDo PArrComp stmts _) = dsPArrComp (map unLoc stmts) -dsExpr (HsDo DoExpr stmts res_ty) = dsDo stmts res_ty -dsExpr (HsDo GhciStmt stmts res_ty) = dsDo stmts res_ty -dsExpr (HsDo MDoExpr stmts res_ty) = dsDo stmts res_ty -dsExpr (HsDo MonadComp stmts res_ty) = dsMonadComp stmts res_ty +dsExpr (HsDo DoExpr stmts _) = dsDo stmts +dsExpr (HsDo GhciStmt stmts _) = dsDo stmts +dsExpr (HsDo MDoExpr stmts _) = dsDo stmts +dsExpr (HsDo MonadComp stmts _) = dsMonadComp stmts dsExpr (HsIf mb_fun guard_expr then_expr else_expr) = do { pred <- dsLExpr guard_expr @@ -694,21 +694,16 @@ handled in DsListComp). Basically does the translation given in the Haskell 98 report: \begin{code} -dsDo :: [LStmt Id] - -> Type -- Type of the whole expression - -> DsM CoreExpr - -dsDo stmts result_ty +dsDo :: [LStmt Id] -> DsM CoreExpr +dsDo stmts = goL stmts where goL [] = panic "dsDo" goL (L loc stmt:lstmts) = putSrcSpanDs loc (go loc stmt lstmts) - go _ (LastStmt body ret_op) stmts - = ASSERT( null stmts ) - do { body' <- dsLExpr body - ; ret_op' <- dsExpr ret_op - ; return (App ret_op' body') } + go _ (LastStmt body _) stmts + = ASSERT( null stmts ) dsLExpr body + -- The 'return' op isn't used for 'do' expressions go _ (ExprStmt rhs then_expr _ _) stmts = do { rhs2 <- dsLExpr rhs @@ -745,6 +740,7 @@ dsDo stmts result_ty noSyntaxExpr -- Tuple cannot fail tup_ids = rec_ids ++ filterOut (`elem` rec_ids) later_ids + tup_ty = mkBoxedTupleTy (map idType tup_ids) -- Deals with singleton case rec_tup_pats = map nlVarPat tup_ids later_pats = rec_tup_pats rets = map noLoc rec_rets @@ -753,8 +749,11 @@ dsDo stmts result_ty (mkFunTy tup_ty body_ty)) mfix_pat = noLoc $ LazyPat $ mkLHsPatTup rec_tup_pats body = noLoc $ HsDo DoExpr (rec_stmts ++ [ret_stmt]) body_ty - ret_stmt = noLoc $ LastStmt return_op (mkLHsTupleExpr rets) - tup_ty = mkBoxedTupleTy (map idType tup_ids) -- Deals with singleton case + ret_app = nlHsApp (noLoc return_op) (mkLHsTupleExpr rets) + ret_stmt = noLoc $ mkLastStmt ret_app + -- This LastStmt will be desugared with dsDo, + -- which ignores the return_op in the LastStmt, + -- so we must apply the return_op explicitly handle_failure :: LPat Id -> MatchResult -> SyntaxExpr Id -> DsM CoreExpr -- In a do expression, pattern-match failure just calls