\begin{code}
module TcHsType (
- tcHsSigType, tcHsDeriv,
+ tcHsSigType, tcHsDeriv,
+ tcHsInstHead, tcHsQuantifiedType,
UserTypeCtxt(..),
-- Kind checking
; checkValidType ctxt ty
; returnM ty }
+tcHsInstHead :: LHsType Name -> TcM ([TyVar], ThetaType, Type)
+-- Typecheck an instance head. We can't use
+-- tcHsSigType, because it's not a valid user type.
+tcHsInstHead hs_ty
+ = do { kinded_ty <- kcHsSigType hs_ty
+ ; poly_ty <- tcHsKindedType kinded_ty
+ ; return (tcSplitSigmaTy poly_ty) }
+
+tcHsQuantifiedType :: [LHsTyVarBndr Name] -> LHsType Name -> TcM ([TyVar], Type)
+-- Behave very like type-checking (HsForAllTy sig_tvs hs_ty),
+-- except that we want to keep the tvs separate
+tcHsQuantifiedType tv_names hs_ty
+ = kcHsTyVars tv_names $ \ tv_names' ->
+ do { kc_ty <- kcHsSigType hs_ty
+ ; tcTyVarBndrs tv_names' $ \ tvs ->
+ do { ty <- dsHsType kc_ty
+ ; return (tvs, ty) } }
+
-- Used for the deriving(...) items
tcHsDeriv :: LHsType Name -> TcM ([TyVar], Class, [Type])
tcHsDeriv = addLocM (tc_hs_deriv [])
-- Does *not* check for a saturated
-- application (reason: used from TcDeriv)
kc_pred pred@(HsIParam name ty)
- = kcHsType ty `thenM` \ (ty', kind) ->
- returnM (HsIParam name ty', kind)
-
+ = do { (ty', kind) <- kcHsType ty
+ ; returnM (HsIParam name ty', kind)
+ }
kc_pred pred@(HsClassP cls tys)
- = kcClass cls `thenM` \ kind ->
- kcApps kind (ppr cls) tys `thenM` \ (tys', res_kind) ->
- returnM (HsClassP cls tys', res_kind)
+ = do { kind <- kcClass cls
+ ; (tys', res_kind) <- kcApps kind (ppr cls) tys
+ ; returnM (HsClassP cls tys', res_kind)
+ }
+kc_pred pred@(HsEqualP ty1 ty2)
+ = do { (ty1', kind1) <- kcHsType ty1
+ ; checkExpectedKind ty1 kind1 liftedTypeKind
+ ; (ty2', kind2) <- kcHsType ty2
+ ; checkExpectedKind ty2 kind2 liftedTypeKind
+ ; returnM (HsEqualP ty1 ty2, liftedTypeKind)
+ }
---------------------------
kcTyVar :: Name -> TcM TcKind
ds_type (HsSpliceTy {}) = panic "ds_type: HsSpliceTy"
+ds_type (HsDocTy ty _) -- Remove the doc comment
+ = dsHsType ty
+
dsHsTypes arg_tys = mappM dsHsType arg_tys
\end{code}
dsHsLPred pred = dsHsPred (unLoc pred)
dsHsPred pred@(HsClassP class_name tys)
- = dsHsTypes tys `thenM` \ arg_tys ->
- tcLookupClass class_name `thenM` \ clas ->
- returnM (ClassP clas arg_tys)
-
+ = do { arg_tys <- dsHsTypes tys
+ ; clas <- tcLookupClass class_name
+ ; returnM (ClassP clas arg_tys)
+ }
+dsHsPred pred@(HsEqualP ty1 ty2)
+ = do { arg_ty1 <- dsHsType ty1
+ ; arg_ty2 <- dsHsType ty2
+ ; returnM (EqPred arg_ty1 arg_ty2)
+ }
dsHsPred (HsIParam name ty)
- = dsHsType ty `thenM` \ arg_ty ->
- returnM (IParam name arg_ty)
+ = do { arg_ty <- dsHsType ty
+ ; returnM (IParam name arg_ty)
+ }
\end{code}
GADT constructor signatures
where
zonk (KindedTyVar name kind) = do { kind' <- zonkTcKindToKind kind
; return (mkTyVar name kind') }
- zonk (UserTyVar name) = pprTrace "Un-kinded tyvar" (ppr name) $
+ zonk (UserTyVar name) = WARN( True, ptext SLIT("Un-kinded tyvar") <+> ppr name )
return (mkTyVar name liftedTypeKind)
-----------------------------------
| n <- nameSetToList (extractHsTyVars hs_ty),
not (in_scope n) ]
- -- Behave very like type-checking (HsForAllTy sig_tvs hs_ty),
- -- except that we want to keep the tvs separate
- ; (kinded_tvs, kinded_ty) <- kcHsTyVars sig_tvs $ \ kinded_tvs -> do
- { kinded_ty <- kcTypeType hs_ty
- ; return (kinded_tvs, kinded_ty) }
- ; tcTyVarBndrs kinded_tvs $ \ tyvars -> do
- { sig_ty <- dsHsType kinded_ty
+ ; (tyvars, sig_ty) <- tcHsQuantifiedType sig_tvs hs_ty
; checkValidType ctxt sig_ty
; return (tyvars, sig_ty)
- } }
+ }
tcPatSig :: UserTypeCtxt
-> LHsType Name