ConDecl(..), Sig(..), NewOrData(..), ResType(..),
tyClDeclTyVars, isSynDecl, isClassDecl, isIdxTyDecl,
isKindSigDecl, hsConArgs, LTyClDecl, tcdName,
ConDecl(..), Sig(..), NewOrData(..), ResType(..),
tyClDeclTyVars, isSynDecl, isClassDecl, isIdxTyDecl,
isKindSigDecl, hsConArgs, LTyClDecl, tcdName,
- hsTyVarName, LHsTyVarBndr, LHsType
+ hsTyVarName, LHsTyVarBndr, LHsType, HsType(..),
+ mkHsAppTy
)
import HsTypes ( HsBang(..), getBangStrictness )
import BasicTypes ( RecFlag(..), StrictnessMark(..) )
)
import HsTypes ( HsBang(..), getBangStrictness )
import BasicTypes ( RecFlag(..), StrictnessMark(..) )
tyConDataCons, mkForeignTyCon, isProductTyCon,
isRecursiveTyCon, isOpenTyCon,
tyConStupidTheta, synTyConRhs, isSynTyCon, tyConName,
tyConDataCons, mkForeignTyCon, isProductTyCon,
isRecursiveTyCon, isOpenTyCon,
tyConStupidTheta, synTyConRhs, isSynTyCon, tyConName,
import DataCon ( DataCon, dataConUserType, dataConName,
dataConFieldLabels, dataConTyCon, dataConAllTyVars,
dataConFieldType, dataConResTys )
import DataCon ( DataCon, dataConUserType, dataConName,
dataConFieldLabels, dataConTyCon, dataConAllTyVars,
dataConFieldType, dataConResTys )
; mod <- getModule
; traceTc (text "tcTyAndCl" <+> ppr mod)
; (syn_tycons, alg_tyclss) <- fixM (\ ~(rec_syn_tycons, rec_alg_tyclss) ->
; mod <- getModule
; traceTc (text "tcTyAndCl" <+> ppr mod)
; (syn_tycons, alg_tyclss) <- fixM (\ ~(rec_syn_tycons, rec_alg_tyclss) ->
- do { let { -- Calculate variances and rec-flag
+ do { let { -- Seperate ordinary synonyms from all other type and
+ -- class declarations and add all associated type
+ -- declarations from type classes. The latter is
+ -- required so that the temporary environment for the
+ -- knot includes all associated family declarations.
- -- We must populate the environment with the loop-tied T's right
- -- away, because the kind checker may "fault in" some type
- -- constructors that recursively mention T
- ; let { gbl_things = mkGlobalThings alg_decls rec_alg_tyclss }
+ -- We must populate the environment with the loop-tied
+ -- T's right away, because the kind checker may "fault
+ -- in" some type constructors that recursively
+ -- mention T
+ ; let gbl_things = mkGlobalThings alg_at_decls rec_alg_tyclss
; tcExtendRecEnv gbl_things $ do
-- Kind-check the declarations
{ (kc_syn_decls, kc_alg_decls) <- kcTyClDecls syn_decls alg_decls
; tcExtendRecEnv gbl_things $ do
-- Kind-check the declarations
{ (kc_syn_decls, kc_alg_decls) <- kcTyClDecls syn_decls alg_decls
; tc_decl = addLocM (tcTyClDecl calc_rec) }
-- Type-check the type synonyms, and extend the envt
; syn_tycons <- tcSynDecls kc_syn_decls
; tc_decl = addLocM (tcTyClDecl calc_rec) }
-- Type-check the type synonyms, and extend the envt
; syn_tycons <- tcSynDecls kc_syn_decls
-- we want them in the environment because
-- they may be mentioned in interface files
; let { implicit_things = concatMap implicitTyThings alg_tyclss }
-- we want them in the environment because
-- they may be mentioned in interface files
; let { implicit_things = concatMap implicitTyThings alg_tyclss }
mkGlobalThings :: [LTyClDecl Name] -- The decls
-> [TyThing] -- Knot-tied, in 1-1 correspondence with the decls
mkGlobalThings :: [LTyClDecl Name] -- The decls
-> [TyThing] -- Knot-tied, in 1-1 correspondence with the decls
tcIdxTyInstDecl (L loc decl)
= -- Prime error recovery, set source location
tcIdxTyInstDecl (L loc decl)
= -- Prime error recovery, set source location
do { -- indexed data types require -fglasgow-exts and can't be in an
-- hs-boot file
; gla_exts <- doptM Opt_GlasgowExts
do { -- indexed data types require -fglasgow-exts and can't be in an
-- hs-boot file
; gla_exts <- doptM Opt_GlasgowExts
- = kcIdxTyPats decl $ \k_tvs k_typats resKind ->
- do { -- kind check the right hand side of the type equation
+ = kcIdxTyPats decl $ \k_tvs k_typats resKind _ ->
+ do { -- (1) kind check the right hand side of the type equation
; t_typats <- mappM tcHsKindedType k_typats
; t_rhs <- tcHsKindedType k_rhs
-- construct type rewrite rule
-- !!!of the form: forall t_tvs. (tcdLName decl) t_typats = t_rhs
; t_typats <- mappM tcHsKindedType k_typats
; t_rhs <- tcHsKindedType k_rhs
-- construct type rewrite rule
-- !!!of the form: forall t_tvs. (tcdLName decl) t_typats = t_rhs
- = kcIdxTyPats decl $ \k_tvs k_typats resKind ->
- do { -- kind check the data declaration as usual
+ = kcIdxTyPats decl $ \k_tvs k_typats resKind family ->
+ do { -- (1) kind check the data declaration as usual
-- result kind must be '*' (otherwise, we have too few patterns)
; checkTc (isLiftedTypeKind resKind) $ tooFewParmsErr tc_name
-- result kind must be '*' (otherwise, we have too few patterns)
; checkTc (isLiftedTypeKind resKind) $ tooFewParmsErr tc_name
- -- type check indexed data type declaration
- ; tcTyVarBndrs k_tvs $ \t_tvs -> do {
+ -- (2) type check indexed data type declaration
+ ; tcTyVarBndrs k_tvs $ \t_tvs -> do { -- turn kinded into proper tyvars
; unbox_strict <- doptM Opt_UnboxStrictFields
-- Check that we don't use GADT syntax for indexed types
; checkTc h98_syntax (badGadtIdxTyDecl tc_name)
-- Check that a newtype has exactly one constructor
; unbox_strict <- doptM Opt_UnboxStrictFields
-- Check that we don't use GADT syntax for indexed types
; checkTc h98_syntax (badGadtIdxTyDecl tc_name)
-- Check that a newtype has exactly one constructor
- ; checkTc (new_or_data == DataType || isSingleton cons) $
- newtypeConError tc_name (length cons)
+ ; checkTc (new_or_data == DataType || isSingleton k_cons) $
+ newtypeConError tc_name (length k_cons)
-- We always assume that indexed types are recursive. Why?
-- (1) Due to their open nature, we can never be sure that a
-- further instance might not introduce a new recursive
-- We always assume that indexed types are recursive. Why?
-- (1) Due to their open nature, we can never be sure that a
-- further instance might not introduce a new recursive
- -- !!!twofold: (1) (ATyCon tycon) and (2) an equality axiom
- ; return Nothing -- !!!TODO: need InstInfo for indexed types
+ -- !!!TODO: missing eq axiom
+ ; return (Nothing, Just (ATyCon tycon))
-- ^^kinded tvs ^^kinded ty pats ^^res kind
-> TcM a
kcIdxTyPats decl thing_inside
= kcHsTyVars (tcdTyVars decl) $ \tvs ->
do { tc_ty_thing <- tcLookupLocated (tcdLName decl)
-- ^^kinded tvs ^^kinded ty pats ^^res kind
-> TcM a
kcIdxTyPats decl thing_inside
= kcHsTyVars (tcdTyVars decl) $ \tvs ->
do { tc_ty_thing <- tcLookupLocated (tcdLName decl)
- ; let tc_kind = case tc_ty_thing of { AThing k -> k }
- (kinds, resKind) = splitKindFunTys tc_kind
- hs_typats = fromJust $ tcdTyPats decl
+ ; let { family = case tc_ty_thing of
+ AGlobal (ATyCon family) -> family
+ ; (kinds, resKind) = splitKindFunTys (tyConKind family)
+ ; hs_typats = fromJust $ tcdTyPats decl }
-- we may not have more parameters than the kind indicates
; checkTc (length kinds >= length hs_typats) $
-- we may not have more parameters than the kind indicates
; checkTc (length kinds >= length hs_typats) $
-- type functions can have a higher-kinded result
; let resultKind = mkArrowKinds (drop (length hs_typats) kinds) resKind
; typats <- zipWithM kcCheckHsType hs_typats kinds
-- type functions can have a higher-kinded result
; let resultKind = mkArrowKinds (drop (length hs_typats) kinds) resKind
; typats <- zipWithM kcCheckHsType hs_typats kinds
-- Check that we don't use kind signatures without Glasgow extensions
; checkTc gla_exts $ badSigTyDecl tc_name
-- Check that we don't use kind signatures without Glasgow extensions
; checkTc gla_exts $ badSigTyDecl tc_name
ASSERT( isSingleton data_cons )
mkNewTyConRhs tc_name tycon (head data_cons)
; buildAlgTyCon tc_name final_tvs stupid_theta tc_rhs is_rec
ASSERT( isSingleton data_cons )
mkNewTyConRhs tc_name tycon (head data_cons)
; buildAlgTyCon tc_name final_tvs stupid_theta tc_rhs is_rec
= tcTyVarBndrs tvs $ \ tvs' -> do
{ ctxt' <- tcHsKindedContext ctxt
; fds' <- mappM (addLocM tc_fundep) fundeps
= tcTyVarBndrs tvs $ \ tvs' -> do
{ ctxt' <- tcHsKindedContext ctxt
; fds' <- mappM (addLocM tc_fundep) fundeps
- ; ats' <- mappM (addLocM (tcTyClDecl1 (const Recursive))) ats
- -- ^^^^ !!!TODO: what to do with this? Need to generate FC tyfun decls.
+ ; atss <- mappM (addLocM (tcTyClDecl1 (const Recursive))) ats
+ ; let ats' = concat atss
; sig_stuff <- tcClassSigs class_name sigs meths
; clas <- fixM (\ clas ->
let -- This little knot is just so we can get
; sig_stuff <- tcClassSigs class_name sigs meths
; clas <- fixM (\ clas ->
let -- This little knot is just so we can get
where
tc_fundep (tvs1, tvs2) = do { tvs1' <- mappM tcLookupTyVar tvs1 ;
; tvs2' <- mappM tcLookupTyVar tvs2 ;
where
tc_fundep (tvs1, tvs2) = do { tvs1' <- mappM tcLookupTyVar tvs1 ;
; tvs2' <- mappM tcLookupTyVar tvs2 ;
(ConDecl name _ ex_tvs ex_ctxt details ResTyH98)
= do { let tc_datacon field_lbls arg_ty
= do { arg_ty' <- tcHsKindedType arg_ty -- No bang on newtype
(ConDecl name _ ex_tvs ex_ctxt details ResTyH98)
= do { let tc_datacon field_lbls arg_ty
= do { arg_ty' <- tcHsKindedType arg_ty -- No bang on newtype
tc_tvs [] -- No existentials
[] [] -- No equalities, predicates
[arg_ty']
tc_tvs [] -- No existentials
[] [] -- No equalities, predicates
[arg_ty']
-- Check that a newtype has no existential stuff
; checkTc (null ex_tvs && null (unLoc ex_ctxt)) (newtypeExError name)
; case details of
-- Check that a newtype has no existential stuff
; checkTc (null ex_tvs && null (unLoc ex_ctxt)) (newtypeExError name)
; case details of
(ConDecl name _ tvs ctxt details res_ty)
= tcTyVarBndrs tvs $ \ tvs' -> do
{ ctxt' <- tcHsKindedContext ctxt
(ConDecl name _ tvs ctxt details res_ty)
= tcTyVarBndrs tvs $ \ tvs' -> do
{ ctxt' <- tcHsKindedContext ctxt
- data_tc }
- -- NB: we put data_tc, the type constructor gotten from the constructor
- -- type signature into the data constructor; that way
- -- checkValidDataCon can complain if it's wrong.
+ data_tc
+ mb_typats}
+ -- NB: we put data_tc, the type constructor gotten from the
+ -- constructor type signature into the data constructor;
+ -- that way checkValidDataCon can complain if it's wrong.