-\end{code}
-
-
-*********************************************************
-* *
-\subsection{Patterns}
-* *
-*********************************************************
-
-\begin{code}
-rnPat :: RdrNamePat -> RnMS (RenamedPat, FreeVars)
-
-rnPat WildPatIn = returnRn (WildPatIn, emptyFVs)
-
-rnPat (VarPatIn name)
- = lookupBndrRn name `thenRn` \ vname ->
- returnRn (VarPatIn vname, emptyFVs)
-
-rnPat (SigPatIn pat ty)
- | opt_GlasgowExts
- = rnPat pat `thenRn` \ (pat', fvs1) ->
- rnHsType doc ty `thenRn` \ (ty', fvs2) ->
- returnRn (SigPatIn pat' ty', fvs1 `plusFV` fvs2)
-
- | otherwise
- = addErrRn (patSigErr ty) `thenRn_`
- rnPat pat
- where
- doc = text "a pattern type-signature"
-
-rnPat (LitPatIn lit)
- = litOccurrence lit `thenRn` \ fvs1 ->
- lookupImplicitOccRn eqClass_RDR `thenRn` \ eq -> -- Needed to find equality on pattern
- returnRn (LitPatIn lit, fvs1 `addOneFV` eq)
-
-rnPat (LazyPatIn pat)
- = rnPat pat `thenRn` \ (pat', fvs) ->
- returnRn (LazyPatIn pat', fvs)
-
-rnPat (AsPatIn name pat)
- = rnPat pat `thenRn` \ (pat', fvs) ->
- lookupBndrRn name `thenRn` \ vname ->
- returnRn (AsPatIn vname pat', fvs)
-
-rnPat (ConPatIn con pats)
- = lookupOccRn con `thenRn` \ con' ->
- mapFvRn rnPat pats `thenRn` \ (patslist, fvs) ->
- returnRn (ConPatIn con' patslist, fvs `addOneFV` con')
-
-rnPat (ConOpPatIn pat1 con _ pat2)
- = rnPat pat1 `thenRn` \ (pat1', fvs1) ->
- lookupOccRn con `thenRn` \ con' ->
- rnPat pat2 `thenRn` \ (pat2', fvs2) ->
-
- getModeRn `thenRn` \ mode ->
- -- See comments with rnExpr (OpApp ...)
- (case mode of
- InterfaceMode -> returnRn (ConOpPatIn pat1' con' defaultFixity pat2')
- SourceMode -> lookupFixityRn con' `thenRn` \ fixity ->
- mkConOpPatRn pat1' con' fixity pat2'
- ) `thenRn` \ pat' ->
- returnRn (pat', fvs1 `plusFV` fvs2 `addOneFV` con')
-
--- Negated patters can only be literals, and they are dealt with
--- by negating the literal at compile time, not by using the negation
--- operation in Num. So we don't need to make an implicit reference
--- to negate_RDR.
-rnPat neg@(NegPatIn pat)
- = checkRn (valid_neg_pat pat) (negPatErr neg)
- `thenRn_`
- rnPat pat `thenRn` \ (pat', fvs) ->
- returnRn (NegPatIn pat', fvs)
- where
- valid_neg_pat (LitPatIn (HsInt _)) = True
- valid_neg_pat (LitPatIn (HsIntPrim _)) = True
- valid_neg_pat (LitPatIn (HsFrac _)) = True
- valid_neg_pat (LitPatIn (HsFloatPrim _)) = True
- valid_neg_pat (LitPatIn (HsDoublePrim _)) = True
- valid_neg_pat _ = False
-
-rnPat (ParPatIn pat)
- = rnPat pat `thenRn` \ (pat', fvs) ->
- returnRn (ParPatIn pat', fvs)
-
-rnPat (NPlusKPatIn name lit)
- = litOccurrence lit `thenRn` \ fvs ->
- lookupImplicitOccRn ordClass_RDR `thenRn` \ ord ->
- lookupBndrRn name `thenRn` \ name' ->
- returnRn (NPlusKPatIn name' lit, fvs `addOneFV` ord)
-
-rnPat (ListPatIn pats)
- = mapFvRn rnPat pats `thenRn` \ (patslist, fvs) ->
- returnRn (ListPatIn patslist, fvs `addOneFV` listTyCon_name)
-
-rnPat (TuplePatIn pats boxed)
- = mapFvRn rnPat pats `thenRn` \ (patslist, fvs) ->
- returnRn (TuplePatIn patslist boxed, fvs `addOneFV` tycon_name)
- where
- tycon_name = tupleTyCon_name boxed (length pats)
-
-rnPat (RecPatIn con rpats)
- = lookupOccRn con `thenRn` \ con' ->
- rnRpats rpats `thenRn` \ (rpats', fvs) ->
- returnRn (RecPatIn con' rpats', fvs `addOneFV` con')
-\end{code}
-
-************************************************************************
-* *
-\subsection{Match}
-* *
-************************************************************************
-
-\begin{code}
-rnMatch :: RdrNameMatch -> RnMS (RenamedMatch, FreeVars)
-
-rnMatch match@(Match _ pats maybe_rhs_sig grhss)
- = pushSrcLocRn (getMatchLoc match) $
-
- -- Find the universally quantified type variables
- -- in the pattern type signatures
- getLocalNameEnv `thenRn` \ name_env ->
- let
- tyvars_in_sigs = rhs_sig_tyvars `unionLists` tyvars_in_pats
- rhs_sig_tyvars = case maybe_rhs_sig of
- Nothing -> []
- Just ty -> extractHsTyRdrTyVars ty
- tyvars_in_pats = extractPatsTyVars pats
- forall_tyvars = filter (not . (`elemFM` name_env)) tyvars_in_sigs
- doc_sig = text "a pattern type-signature"
- doc_pats = text "in a pattern match"
- in
- bindTyVarsFVRn doc_sig (map UserTyVar forall_tyvars) $ \ sig_tyvars ->
-
- -- Note that we do a single bindLocalsRn for all the
- -- matches together, so that we spot the repeated variable in
- -- f x x = 1
- bindLocalsFVRn doc_pats (collectPatsBinders pats) $ \ new_binders ->
-
- mapFvRn rnPat pats `thenRn` \ (pats', pat_fvs) ->
- rnGRHSs grhss `thenRn` \ (grhss', grhss_fvs) ->
- (case maybe_rhs_sig of
- Nothing -> returnRn (Nothing, emptyFVs)
- Just ty | opt_GlasgowExts -> rnHsType doc_sig ty `thenRn` \ (ty', ty_fvs) ->
- returnRn (Just ty', ty_fvs)
- | otherwise -> addErrRn (patSigErr ty) `thenRn_`
- returnRn (Nothing, emptyFVs)
- ) `thenRn` \ (maybe_rhs_sig', ty_fvs) ->