+
+%************************************************************************
+%* *
+\subsection{Free variables of declarations}
+%* *
+%************************************************************************
+
+Return the Names that must be in scope if we are to use this declaration.
+In all cases this is set up for interface-file declarations:
+ - for class decls we ignore the bindings
+ - for instance decls likewise, plus the pragmas
+ - for rule decls, we ignore HsRules
+ - for data decls, we ignore derivings
+
+ *** See "THE NAMING STORY" in HsDecls ****
+
+\begin{code}
+----------------
+hsSigsFVs :: [LSig Name] -> FreeVars
+hsSigsFVs sigs = plusFVs (map (hsSigFVs.unLoc) sigs)
+
+hsSigFVs (Sig v ty) = extractHsTyNames ty
+hsSigFVs (SpecInstSig ty) = extractHsTyNames ty
+hsSigFVs (SpecSig v ty) = extractHsTyNames ty
+hsSigFVs other = emptyFVs
+
+----------------
+conDeclFVs (L _ (ConDecl _ tyvars context details))
+ = delFVs (map hsLTyVarName tyvars) $
+ extractHsCtxtTyNames context `plusFV`
+ conDetailsFVs details
+
+conDetailsFVs (PrefixCon btys) = plusFVs (map bangTyFVs btys)
+conDetailsFVs (InfixCon bty1 bty2) = bangTyFVs bty1 `plusFV` bangTyFVs bty2
+conDetailsFVs (RecCon flds) = plusFVs [bangTyFVs bty | (_, bty) <- flds]
+
+bangTyFVs bty = extractHsTyNames (getBangType (unLoc bty))
+\end{code}
+
+
+%************************************************************************
+%* *
+\subsection{A few functions on generic defintions
+%* *
+%************************************************************************
+
+These functions on generics are defined over Matches Name, which is
+why they are here and not in HsMatches.
+
+\begin{code}
+maybeGenericMatch :: LMatch Name -> Maybe (HsType Name, LMatch Name)
+ -- Tells whether a Match is for a generic definition
+ -- and extract the type from a generic match and put it at the front
+
+maybeGenericMatch (L loc (Match (L _ (TypePat (L _ ty)) : pats) sig_ty grhss))
+ = Just (ty, L loc (Match pats sig_ty grhss))
+
+maybeGenericMatch other_match = Nothing
+\end{code}