--- | Extracts the named binder from the given module.
-findBind ::
- GhcMonad m =>
- String -- ^ The Name of the Binder
- -> HscTypes.CoreModule -- ^ The Module to look in
- -> m (Maybe CoreBndr) -- ^ The resulting binder
-findBind name core =
- case (findBinder (CoreSyn.flattenBinds $ cm_binds core)) name of
- Nothing -> return Nothing
- Just bndr -> return $ Just $ fst bndr
-
--- | Extracts the named expression from the given module.
-findExpr ::
- GhcMonad m =>
- String -- ^ The Name of the Binder
- -> HscTypes.CoreModule -- ^ The Module to look in
- -> m (Maybe CoreExpr) -- ^ The resulting expression
-findExpr name core =
- case (findBinder (CoreSyn.flattenBinds $ cm_binds core)) name of
- Nothing -> return Nothing
- Just bndr -> return $ Just $ snd bndr
-
--- | Extract a named bind from the given list of binds
-findBinder :: [(CoreBndr, CoreExpr)] -> String -> Maybe (CoreBndr, CoreExpr)
-findBinder binds lookfor =
- -- This ignores Recs and compares the name of the bind with lookfor,
- -- disregarding any namespaces in OccName and extra attributes in Name and
- -- Var.
- find (\(var, _) -> lookfor == (occNameString $ nameOccName $ getName var)) binds
+-- | Determine if a binder has a certain name
+hasVarName ::
+ GhcMonad m => -- ^ Exprected to be run in some kind of GHC Monad
+ String -- ^ The name the binder has to have
+ -> Var.Var -- ^ The Binder
+ -> m Bool -- ^ Indicate if the binder has the name
+hasVarName lookfor bind = return $ lookfor == (occNameString $ nameOccName $ getName bind)