+kc_check_lhs_type (L span ty) exp_kind
+ = setSrcSpan span $
+ do { ty' <- kc_check_hs_type ty exp_kind
+ ; return (L span ty') }
+
+kc_check_lhs_types :: [(LHsType Name,TcKind)] -> TcM [LHsType Name]
+kc_check_lhs_types tys_w_kinds
+ = mapM kc_arg tys_w_kinds
+ where
+ kc_arg (arg, arg_kind) = kc_check_lhs_type arg arg_kind
+
+
+---------------------------
+kc_check_hs_type :: HsType Name -> TcKind -> TcM (HsType Name)
+
+-- First some special cases for better error messages
+-- when we know the expected kind
+kc_check_hs_type (HsParTy ty) exp_kind
+ = do { ty' <- kc_check_lhs_type ty exp_kind; return (HsParTy ty') }
+
+kc_check_hs_type ty@(HsAppTy ty1 ty2) exp_kind
+ = do { let (fun_ty, arg_tys) = splitHsAppTys ty1 ty2
+ ; (fun_ty', fun_kind) <- kc_lhs_type fun_ty
+ ; arg_tys' <- kcCheckApps fun_ty fun_kind arg_tys ty exp_kind
+ ; return (mkHsAppTys fun_ty' arg_tys') }
+
+kc_check_hs_type ty@(HsPredTy (HsClassP cls tys)) exp_kind
+ = do { cls_kind <- kcClass cls
+ ; tys' <- kcCheckApps cls cls_kind tys ty exp_kind
+ ; return (HsPredTy (HsClassP cls tys')) }
+
+-- This is the general case: infer the kind and compare
+kc_check_hs_type ty exp_kind
+ = do { (ty', act_kind) <- kc_hs_type ty