-tcTyVarScopeGivenKinds
- :: [Name] -- Names of some type variables
- -> [TcKind s]
- -> ([TyVar] -> TcM s a) -- Thing to type check in their scope
- -> TcM s a -- Result
-
-tcTyVarScopeGivenKinds names kinds thing_inside
- = fixTc (\ ~(rec_tyvars, _) ->
- -- Ok to look at names, kinds, but not tyvars!
-
- tcGetEnv `thenNF_Tc` \ (TcEnv tve tce ce gve lve gtvs) ->
- let
- tve' = addListToUFM tve (zipEqual "tcTyVarScopeGivenKinds" names (kinds `zipLazy` rec_tyvars))
- in
- tcSetEnv (TcEnv tve' tce ce gve lve gtvs)
- (thing_inside rec_tyvars) `thenTc` \ result ->
-
- -- Get the tyvar's Kinds from their TcKinds
- mapNF_Tc tcDefaultKind kinds `thenNF_Tc` \ kinds' ->
-
- -- Construct the real TyVars
- let
- tyvars = zipWithEqual "tcTyVarScopeGivenKinds" mkTyVar names kinds'
- in
- returnTc (tyvars, result)
- ) `thenTc` \ (_,result) ->
- returnTc result
-
-tcTyVarScope names thing_inside
- = newKindVars (length names) `thenNF_Tc` \ kinds ->
- tcTyVarScopeGivenKinds names kinds thing_inside
+type TcId = Id -- Type may be a TcType
+type TcIdSet = IdSet
+
+tcLookupDataCon :: Name -> TcM s (DataCon, [TcType], TcType)
+tcLookupDataCon con_name
+ = tcLookupValue con_name `thenNF_Tc` \ con_id ->
+ case isDataConWrapId_maybe con_id of {
+ Nothing -> failWithTc (badCon con_id);
+ Just data_con ->
+
+ tcInstId con_id `thenNF_Tc` \ (_, _, con_tau) ->
+ -- Ignore the con_theta; overloaded constructors only
+ -- behave differently when called, not when used for
+ -- matching.
+ let
+ (arg_tys, result_ty) = splitFunTys con_tau
+ in
+ ASSERT( maybeToBool (splitAlgTyConApp_maybe result_ty) )
+ returnTc (data_con, arg_tys, result_ty) }
+
+-- A useful function that takes an occurrence of a global thing
+-- and instantiates its type with fresh type variables
+tcInstId :: Id
+ -> NF_TcM s ([TcTyVar], -- It's instantiated type
+ TcThetaType, --
+ TcType) --
+tcInstId id
+ = let
+ (tyvars, rho) = splitForAllTys (unannotTy (idType id))
+ in
+ tcInstTyVars tyvars `thenNF_Tc` \ (tyvars', arg_tys, tenv) ->
+ let
+ rho' = substTy tenv rho
+ (theta', tau') = splitRhoTy rho'
+ in
+ returnNF_Tc (tyvars', theta', tau')