-tc_lam_pats :: PatCtxt
- -> [(LPat Name,BoxySigmaType)]
- -> BoxyRhoType -- Result type
- -> (BoxyRhoType -> TcM a) -- Checker for body, given its result type
- -> TcM ([LPat TcId], a)
-tc_lam_pats ctxt pat_ty_prs res_ty thing_inside
- = do { let init_state = PS { pat_ctxt = ctxt, pat_eqs = False }
+data PatEnv
+ = PE { pe_res_tvs :: TcTyVarSet
+ -- For existential escape check; see Note [Existential check]
+ -- Nothing <=> inside a "~"
+ -- Just tvs <=> unification tvs free in the result
+ -- (which should be made untouchable in
+ -- any existentials we encounter in the pattern)
+
+ , pe_lazy :: Bool -- True <=> lazy context, so no existentials allowed
+ , pe_ctxt :: PatCtxt -- Context in which the whole pattern appears
+ }
+
+data PatCtxt
+ = LamPat -- Used for lambdas, case etc
+ (HsMatchContext Name)
+
+ | LetPat -- Used only for let(rec) bindings
+ -- See Note [Let binders]
+ TcSigFun -- Tells type sig if any
+ LetBndrSpec -- True <=> no generalisation of this let
+
+data LetBndrSpec
+ = LetLclBndr -- The binder is just a local one;
+ -- an AbsBinds will provide the global version
+
+ | LetGblBndr TcPragFun -- There isn't going to be an AbsBinds;
+ -- here is the inline-pragma information
+
+makeLazy :: PatEnv -> PatEnv
+makeLazy penv = penv { pe_lazy = True }
+
+patSigCtxt :: PatEnv -> UserTypeCtxt
+patSigCtxt (PE { pe_ctxt = LetPat {} }) = BindPatSigCtxt
+patSigCtxt (PE { pe_ctxt = LamPat {} }) = LamPatSigCtxt
+
+---------------
+type TcPragFun = Name -> [LSig Name]
+type TcSigFun = Name -> Maybe TcSigInfo
+
+data TcSigInfo
+ = TcSigInfo {
+ sig_id :: TcId, -- *Polymorphic* binder for this value...
+
+ sig_scoped :: [Name], -- Scoped type variables
+ -- 1-1 correspondence with a prefix of sig_tvs
+ -- However, may be fewer than sig_tvs;
+ -- see Note [More instantiated than scoped]
+ sig_tvs :: [TcTyVar], -- Instantiated type variables
+ -- See Note [Instantiate sig]
+
+ sig_theta :: TcThetaType, -- Instantiated theta
+
+ sig_tau :: TcSigmaType, -- Instantiated tau
+ -- See Note [sig_tau may be polymorphic]
+
+ sig_loc :: SrcSpan -- The location of the signature
+ }
+
+instance Outputable TcSigInfo where
+ ppr (TcSigInfo { sig_id = id, sig_tvs = tyvars, sig_theta = theta, sig_tau = tau})
+ = ppr id <+> ptext (sLit "::") <+> ppr tyvars <+> pprThetaArrow theta <+> ppr tau
+\end{code}