data HsBind id
= FunBind { -- FunBind is used for both functions f x = e
-- and variables f = \x -> e
--- Reason 1: the Match stuff lets us have an optional
--- result type sig f :: a->a = ...mentions a...
+-- Reason 1: Special case for type inference: see TcBinds.tcMonoBinds
--
--- Reason 2: Special case for type inference: see TcBinds.tcMonoBinds
---
--- Reason 3: instance decls can only have FunBinds, which is convenient
+-- Reason 2: instance decls can only have FunBinds, which is convenient
-- If you change this, you'll need tochange e.g. rnMethodBinds
+-- But note that the form f :: a->a = ...
+-- parses as a pattern binding, just like
+-- (f :: a -> a) = ...
+
fun_id :: Located id,
fun_infix :: Bool, -- True => infix declaration
-> Located (GRHSs RdrName)
-> P (HsBind RdrName)
+checkValDef lhs (Just sig) grhss
+ -- x :: ty = rhs parses as a *pattern* binding
+ = checkPatBind (L (combineLocs lhs sig) (ExprWithTySig lhs sig)) grhss
+
checkValDef lhs opt_sig grhss
= do { mb_fun <- isFunLhs lhs
; case mb_fun of
ExprCoFn )
import TcRnMonad
-import TcHsType ( tcPatSig, UserTypeCtxt(..) )
import Inst ( newMethodFromName )
-import TcEnv ( TcId, tcLookupLocalIds, tcLookupId, tcExtendIdEnv,
- tcExtendTyVarEnv2 )
+import TcEnv ( TcId, tcLookupLocalIds, tcLookupId, tcExtendIdEnv )
import TcPat ( PatCtxt(..), tcPats, tcPat )
import TcMType ( newFlexiTyVarTy, newFlexiTyVarTys )
import TcType ( TcType, TcRhoType,
= addErrCtxt (matchCtxt (mc_what ctxt) match) $
do { (pats', grhss') <- tcPats LamPat pats pat_tys rhs_ty $
tc_grhss ctxt maybe_rhs_sig grhss
- ; returnM (Match pats' Nothing grhss') }
+ ; return (Match pats' Nothing grhss') }
tc_grhss ctxt Nothing grhss rhs_ty
= tcGRHSs ctxt grhss rhs_ty -- No result signature
+ -- Result type sigs are no longer supported
tc_grhss ctxt (Just res_sig) grhss rhs_ty
- = do { (inner_ty, sig_tvs) <- tcPatSig ResSigCtxt res_sig rhs_ty
- ; tcExtendTyVarEnv2 sig_tvs $
- tcGRHSs ctxt grhss inner_ty }
+ = do { addErr (ptext SLIT("Ignoring (deprecated) result type signature")
+ <+> ppr res_sig)
+ ; tcGRHSs ctxt grhss rhs_ty }
-------------
tcGRHSs :: TcMatchCtxt -> GRHSs Name -> BoxyRhoType -> TcM (GRHSs TcId)
args_in_match :: LMatch Name -> Int
args_in_match (L _ (Match pats _ _)) = length pats
+checkArgs fun other = panic "TcPat.checkArgs" -- Matches always non-empty
\end{code}
\begin{code}