diff options
author | Ian Lynagh <igloo@earth.li> | 2011-10-26 19:06:53 +0100 |
---|---|---|
committer | Ian Lynagh <igloo@earth.li> | 2011-10-26 19:06:53 +0100 |
commit | 6f5b798bc6a94a12dd3122a62e4e97af528c8c75 (patch) | |
tree | ae900019bfd0e526b06cb3185ef3c5a73b3b6e91 /compiler | |
parent | 115b3df1ced3d8a49d2d50631cf996afececdd29 (diff) | |
parent | 7437af6f36b8201fba7a9dea98685da4d35f167f (diff) | |
download | haskell-6f5b798bc6a94a12dd3122a62e4e97af528c8c75.tar.gz |
Merge branch 'master' of http://darcs.haskell.org/ghc
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/typecheck/TcArrows.lhs | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/compiler/typecheck/TcArrows.lhs b/compiler/typecheck/TcArrows.lhs index 774cea5c51..0dfe8b0f1e 100644 --- a/compiler/typecheck/TcArrows.lhs +++ b/compiler/typecheck/TcArrows.lhs @@ -119,17 +119,28 @@ tc_cmd env in_cmd@(HsCase scrut matches) (stk, res_ty) mc_body = mc_body } mc_body body res_ty' = tcCmd env body (stk, res_ty') -tc_cmd env (HsIf mb_fun pred b1 b2) (stack_ty,res_ty) +tc_cmd env (HsIf Nothing pred b1 b2) res_ty -- Ordinary 'if' + = do { pred' <- tcMonoExpr pred boolTy + ; b1' <- tcCmd env b1 res_ty + ; b2' <- tcCmd env b2 res_ty + ; return (HsIf Nothing pred' b1' b2') + } + +tc_cmd env (HsIf (Just fun) pred b1 b2) res_ty -- Rebindable syntax for if = do { pred_ty <- newFlexiTyVarTy openTypeKind - ; b_ty <- newFlexiTyVarTy openTypeKind - ; let if_ty = mkFunTys [pred_ty, b_ty, b_ty] res_ty - ; mb_fun' <- case mb_fun of - Nothing -> return Nothing - Just fun -> liftM Just (tcSyntaxOp IfOrigin fun if_ty) + -- For arrows, need ifThenElse :: forall r. T -> r -> r -> r + -- because we're going to apply it to the environment, not + -- the return value. + ; [r_tv] <- tcInstSkolTyVars [alphaTyVar] + ; let r_ty = mkTyVarTy r_tv + ; let if_ty = mkFunTys [pred_ty, r_ty, r_ty] r_ty + ; checkTc (not (r_tv `elemVarSet` tyVarsOfType pred_ty)) + (ptext (sLit "Predicate type of `ifThenElse' depends on result type")) + ; fun' <- tcSyntaxOp IfOrigin fun if_ty ; pred' <- tcMonoExpr pred pred_ty - ; b1' <- tcCmd env b1 (stack_ty,b_ty) - ; b2' <- tcCmd env b2 (stack_ty,b_ty) - ; return (HsIf mb_fun' pred' b1' b2') + ; b1' <- tcCmd env b1 res_ty + ; b2' <- tcCmd env b2 res_ty + ; return (HsIf (Just fun') pred' b1' b2') } ------------------------------------------- |