Commit 6f5b798b authored by Ian Lynagh's avatar Ian Lynagh
Browse files

Merge branch 'master' of http://darcs.haskell.org/ghc

parents 115b3df1 7437af6f
...@@ -119,17 +119,28 @@ tc_cmd env in_cmd@(HsCase scrut matches) (stk, res_ty) ...@@ -119,17 +119,28 @@ tc_cmd env in_cmd@(HsCase scrut matches) (stk, res_ty)
mc_body = mc_body } mc_body = mc_body }
mc_body body res_ty' = tcCmd env body (stk, res_ty') 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 = do { pred_ty <- newFlexiTyVarTy openTypeKind
; b_ty <- newFlexiTyVarTy openTypeKind -- For arrows, need ifThenElse :: forall r. T -> r -> r -> r
; let if_ty = mkFunTys [pred_ty, b_ty, b_ty] res_ty -- because we're going to apply it to the environment, not
; mb_fun' <- case mb_fun of -- the return value.
Nothing -> return Nothing ; [r_tv] <- tcInstSkolTyVars [alphaTyVar]
Just fun -> liftM Just (tcSyntaxOp IfOrigin fun if_ty) ; 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 ; pred' <- tcMonoExpr pred pred_ty
; b1' <- tcCmd env b1 (stack_ty,b_ty) ; b1' <- tcCmd env b1 res_ty
; b2' <- tcCmd env b2 (stack_ty,b_ty) ; b2' <- tcCmd env b2 res_ty
; return (HsIf mb_fun' pred' b1' b2') ; return (HsIf (Just fun') pred' b1' b2')
} }
------------------------------------------- -------------------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment