\begin{code}
module TcMonoType ( tcHsType, tcHsRecType,
- tcHsSigType, tcHsBoxedSigType,
+ tcHsSigType, tcHsLiftedSigType,
tcRecClassContext, checkAmbiguity,
-- Kind checking
kcHsTyVar, kcHsTyVars, mkTyClTyVars,
- kcHsType, kcHsSigType, kcHsBoxedSigType, kcHsContext,
+ kcHsType, kcHsSigType, kcHsLiftedSigType, kcHsContext,
tcTyVars, tcHsTyVars, mkImmutTyVars,
TcSigInfo(..), tcTySig, mkTcSig, maybeSig,
)
import Inst ( Inst, InstOrigin(..), newMethodWithGivenTy, instToIdBndr,
instFunDeps, instFunDepsOfTheta )
-import FunDeps ( tyVarFunDep, oclose )
+import FunDeps ( oclose )
import TcUnify ( unifyKind, unifyOpenTypeKind )
-import Type ( Type, Kind, PredType(..), ThetaType,
+import Type ( Type, Kind, PredType(..), ThetaType, SigmaType, TauType,
mkTyVarTy, mkTyVarTys, mkFunTy, mkSynTy,
zipFunTys, hoistForAllTys,
mkSigmaTy, mkPredTy, mkTyConApp,
mkAppTys, splitForAllTys, splitRhoTy, mkRhoTy,
- boxedTypeKind, unboxedTypeKind, mkArrowKind,
+ liftedTypeKind, unliftedTypeKind, mkArrowKind,
mkArrowKinds, getTyVar_maybe, getTyVar, splitFunTy_maybe,
tidyOpenType, tidyOpenTypes, tidyTyVar, tidyTyVars,
tyVarsOfType, tyVarsOfPred, mkForAllTys,
)
import PprType ( pprType, pprPred )
import Subst ( mkTopTyVarSubst, substTy )
-import Id ( mkVanillaId, idName, idType, idFreeTyVars )
+import CoreFVs ( idFreeTyVars )
+import Id ( mkVanillaId, idName, idType )
import Var ( Id, Var, TyVar, mkTyVar, tyVarKind )
import VarEnv
import VarSet
returnNF_Tc (name, kind)
---------------------------
-kcBoxedType :: RenamedHsType -> TcM ()
- -- The type ty must be a *boxed* *type*
-kcBoxedType ty
+kcLiftedType :: RenamedHsType -> TcM ()
+ -- The type ty must be a *lifted* *type*
+kcLiftedType ty
= kcHsType ty `thenTc` \ kind ->
tcAddErrCtxt (typeKindCtxt ty) $
- unifyKind boxedTypeKind kind
+ unifyKind liftedTypeKind kind
---------------------------
kcTypeType :: RenamedHsType -> TcM ()
- -- The type ty must be a *type*, but it can be boxed or unboxed.
+ -- The type ty must be a *type*, but it can be lifted or unlifted.
kcTypeType ty
= kcHsType ty `thenTc` \ kind ->
tcAddErrCtxt (typeKindCtxt ty) $
unifyOpenTypeKind kind
---------------------------
-kcHsSigType, kcHsBoxedSigType :: RenamedHsType -> TcM ()
+kcHsSigType, kcHsLiftedSigType :: RenamedHsType -> TcM ()
-- Used for type signatures
kcHsSigType = kcTypeType
-kcHsBoxedSigType = kcBoxedType
+kcHsLiftedSigType = kcLiftedType
---------------------------
kcHsType :: RenamedHsType -> TcM TcKind
kcHsType (HsTyVar name) = kcTyVar name
kcHsType (HsListTy ty)
- = kcBoxedType ty `thenTc` \ tau_ty ->
- returnTc boxedTypeKind
+ = kcLiftedType ty `thenTc` \ tau_ty ->
+ returnTc liftedTypeKind
-kcHsType (HsTupleTy (HsTupCon _ boxity) tys)
+kcHsType (HsTupleTy (HsTupCon _ boxity _) tys)
= mapTc kcTypeType tys `thenTc_`
returnTc (case boxity of
- Boxed -> boxedTypeKind
- Unboxed -> unboxedTypeKind)
+ Boxed -> liftedTypeKind
+ Unboxed -> unliftedTypeKind)
kcHsType (HsFunTy ty1 ty2)
= kcTypeType ty1 `thenTc_`
kcTypeType ty2 `thenTc_`
- returnTc boxedTypeKind
+ returnTc liftedTypeKind
kcHsType ty@(HsOpTy ty1 op ty2)
= kcTyVar op `thenTc` \ op_kind ->
kcHsType (HsPredTy pred)
= kcHsPred pred `thenTc_`
- returnTc boxedTypeKind
+ returnTc liftedTypeKind
kcHsType ty@(HsAppTy ty1 ty2)
= kcHsType ty1 `thenTc` \ tc_kind ->
tcExtendKindEnv kind_env $
kcHsContext context `thenTc_`
kcHsType ty `thenTc_`
- returnTc boxedTypeKind
+ returnTc liftedTypeKind
---------------------------
kcAppKind fun_kind arg_kind
kcHsPred :: RenamedHsPred -> TcM ()
kcHsPred pred@(HsPIParam name ty)
= tcAddErrCtxt (appKindCtxt (ppr pred)) $
- kcBoxedType ty
+ kcLiftedType ty
kcHsPred pred@(HsPClass cls tys)
= tcAddErrCtxt (appKindCtxt (ppr pred)) $
kcClass cls `thenTc` \ kind ->
mapTc kcHsType tys `thenTc` \ arg_kinds ->
- unifyKind kind (mkArrowKinds arg_kinds boxedTypeKind)
+ unifyKind kind (mkArrowKinds arg_kinds liftedTypeKind)
---------------------------
kcTyVar name -- Could be a tyvar or a tycon
%* *
%************************************************************************
-tcHsSigType and tcHsBoxedSigType
+tcHsSigType and tcHsLiftedSigType
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-tcHsSigType and tcHsBoxedSigType are used for type signatures written by the programmer
+tcHsSigType and tcHsLiftedSigType are used for type signatures written by the programmer
* We hoist any inner for-alls to the top
so the kind returned is indeed a Kind not a TcKind
\begin{code}
-tcHsSigType, tcHsBoxedSigType :: RenamedHsType -> TcM Type
+tcHsSigType, tcHsLiftedSigType :: RenamedHsType -> TcM Type
-- Do kind checking, and hoist for-alls to the top
tcHsSigType ty = kcTypeType ty `thenTc_` tcHsType ty
-tcHsBoxedSigType ty = kcBoxedType ty `thenTc_` tcHsType ty
+tcHsLiftedSigType ty = kcLiftedType ty `thenTc_` tcHsType ty
tcHsType :: RenamedHsType -> TcM Type
tcHsRecType :: RecFlag -> RenamedHsType -> TcM Type
= tc_arg_type wimp_out ty `thenTc` \ tau_ty ->
returnTc (mkListTy tau_ty)
-tc_type wimp_out (HsTupleTy (HsTupCon _ boxity) tys)
- = mapTc tc_tup_arg tys `thenTc` \ tau_tys ->
- returnTc (mkTupleTy boxity (length tys) tau_tys)
+tc_type wimp_out (HsTupleTy (HsTupCon _ boxity arity) tys)
+ = ASSERT( arity == length tys )
+ mapTc tc_tup_arg tys `thenTc` \ tau_tys ->
+ returnTc (mkTupleTy boxity arity tau_tys)
where
tc_tup_arg = case boxity of
Boxed -> tc_arg_type wimp_out
because the test can't fail (see is_ambig).
\begin{code}
+checkAmbiguity :: RecFlag -> Bool
+ -> [TyVar] -> ThetaType -> TauType
+ -> TcM SigmaType
checkAmbiguity wimp_out is_source_polytype forall_tyvars theta tau
| isRec wimp_out = returnTc sigma_ty
| otherwise = mapTc_ check_pred theta `thenTc_`
sigma_ty = mkSigmaTy forall_tyvars theta tau
tau_vars = tyVarsOfType tau
fds = instFunDepsOfTheta theta
- tvFundep = tyVarFunDep fds
- extended_tau_vars = oclose tvFundep tau_vars
+ extended_tau_vars = oclose fds tau_vars
is_ambig ct_var = (ct_var `elem` forall_tyvars) &&
not (ct_var `elemUFM` extended_tau_vars)