+
+%************************************************************************
+%* *
+\subsection{Getting patterns out of bindings}
+%* *
+%************************************************************************
+
+Get all the pattern type signatures out of a bunch of bindings
+
+\begin{code}
+collectSigTysFromHsBinds :: [LHsBind name] -> [LHsType name]
+collectSigTysFromHsBinds binds = concat (map collectSigTysFromHsBind binds)
+
+collectSigTysFromHsBind :: LHsBind name -> [LHsType name]
+collectSigTysFromHsBind bind
+ = go (unLoc bind)
+ where
+ go (PatBind pat _) = collectSigTysFromPat pat
+ go (FunBind f _ ms) = go_matches (map unLoc ms)
+
+ -- A binding like x :: a = f y
+ -- is parsed as FunMonoBind, but for this purpose we
+ -- want to treat it as a pattern binding
+ go_matches [] = []
+ go_matches (Match [] (Just sig) _ : matches) = sig : go_matches matches
+ go_matches (match : matches) = go_matches matches
+\end{code}
+
+\begin{code}
+collectStmtsBinders :: [LStmt id] -> [Located id]
+collectStmtsBinders = concatMap collectLStmtBinders
+
+collectLStmtBinders = collectStmtBinders . unLoc
+
+collectStmtBinders :: Stmt id -> [Located id]
+ -- Id Binders for a Stmt... [but what about pattern-sig type vars]?
+collectStmtBinders (BindStmt pat _) = collectLocatedPatBinders pat
+collectStmtBinders (LetStmt binds) = collectGroupBinders binds
+collectStmtBinders (ExprStmt _ _) = []
+collectStmtBinders (ResultStmt _) = []
+collectStmtBinders (RecStmt ss _ _ _) = collectStmtsBinders ss
+collectStmtBinders other = panic "collectStmtBinders"
+\end{code}