+tc_pat tc_bndr pat@(TypePat ty) pat_ty
+ = failWithTc (badTypePat pat)
+
+tc_pat tc_bndr (VarPat name) pat_ty
+ = tc_bndr name pat_ty `thenM` \ (co_fn, bndr_id) ->
+ returnM (co_fn <$> VarPat bndr_id,
+ emptyBag, unitBag (name, bndr_id), [])
+
+tc_pat tc_bndr (LazyPat pat) pat_ty
+ = tcPat tc_bndr pat pat_ty `thenM` \ (pat', tvs, ids, lie_avail) ->
+ returnM (LazyPat pat', tvs, ids, lie_avail)
+
+tc_pat tc_bndr pat_in@(AsPat (L nm_loc name) pat) pat_ty
+ = addSrcSpan nm_loc (tc_bndr name pat_ty) `thenM` \ (co_fn, bndr_id) ->
+ tcPat tc_bndr pat (Check (idType bndr_id)) `thenM` \ (pat', tvs, ids, lie_avail) ->
+ -- NB: if we have:
+ -- \ (y@(x::forall a. a->a)) = e
+ -- we'll fail. The as-pattern infers a monotype for 'y', which then
+ -- fails to unify with the polymorphic type for 'x'. This could be
+ -- fixed, but only with a bit more work.
+ returnM (co_fn <$> (AsPat (L nm_loc bndr_id) pat'),
+ tvs, (name, bndr_id) `consBag` ids, lie_avail)
+
+tc_pat tc_bndr (WildPat _) pat_ty
+ = zapExpectedType pat_ty argTypeKind `thenM` \ pat_ty' ->
+ -- We might have an incoming 'hole' type variable; no annotation
+ -- so zap it to a type. Rather like tcMonoPatBndr.
+ -- Note argTypeKind, so that
+ -- f _ = 3
+ -- is rejected when f applied to an unboxed tuple
+ -- However, this means that
+ -- (case g x of _ -> ...)
+ -- is rejected g returns an unboxed tuple, which is perhpas
+ -- annoying. I suppose we could pass the context into tc_pat...
+ returnM (WildPat pat_ty', emptyBag, emptyBag, [])
+
+tc_pat tc_bndr (ParPat parend_pat) pat_ty
+-- Leave the parens in, so that warnings from the
+-- desugarer have parens in them
+ = tcPat tc_bndr parend_pat pat_ty `thenM` \ (pat', tvs, ids, lie_avail) ->
+ returnM (ParPat pat', tvs, ids, lie_avail)
+
+tc_pat tc_bndr pat_in@(SigPatIn pat sig) pat_ty
+ = addErrCtxt (patCtxt pat_in) $
+ tcHsSigType PatSigCtxt sig `thenM` \ sig_ty ->
+ tcSubPat sig_ty pat_ty `thenM` \ co_fn ->
+ tcPat tc_bndr pat (Check sig_ty) `thenM` \ (pat', tvs, ids, lie_avail) ->
+ returnM (co_fn <$> unLoc pat', tvs, ids, lie_avail)
+\end{code}