-\begin{code}
-tcMatchPats :: [LPat Name]
- -> [Expected TcSigmaType] -- Pattern types
- -> Expected TcRhoType -- Result type;
- -- used only to check existential escape
- -> TcM a
- -> TcM ([LPat TcId], a)
--- Typecheck the patterns, extend the environment to bind the variables,
--- do the thing inside, use any existentially-bound dictionaries to
--- discharge parts of the returning LIE, and deal with pattern type
--- signatures
-
-tcMatchPats pats tys body_ty thing_inside
- = do { (pats', ex_tvs, res) <- tcPats LamPat pats tys thing_inside
- ; tcCheckExistentialPat pats' ex_tvs tys body_ty
- ; returnM (pats', res) }
-
-tcCheckExistentialPat :: [LPat TcId] -- Patterns (just for error message)
- -> [TcTyVar] -- Existentially quantified tyvars bound by pattern
- -> [Expected TcSigmaType] -- Types of the patterns
- -> Expected TcRhoType -- Type of the body of the match
- -- Tyvars in either of these must not escape
- -> TcM ()
- -- NB: we *must* pass "pats_tys" not just "body_ty" to tcCheckExistentialPat
- -- For example, we must reject this program:
- -- data C = forall a. C (a -> Int)
- -- f (C g) x = g x
- -- Here, result_ty will be simply Int, but expected_ty is (C -> a -> Int).
-
-tcCheckExistentialPat pats [] pat_tys body_ty
- = return () -- Short cut for case when there are no existentials
-
-tcCheckExistentialPat pats ex_tvs pat_tys body_ty
- = do { tys <- mapM readExpectedType (body_ty : pat_tys)
- ; addErrCtxtM (sigPatCtxt (collectPatsBinders pats) ex_tvs tys) $
- checkSigTyVarsWrt (tyVarsOfTypes tys) ex_tvs }