-- | Lookup a declaration in the optimizer state by its identifier.
findDecl :: Name -> Opti (Maybe Expr)
findDecl name = do
  st <- get
  let decl = find (\d -> case d of
                      PDecl dname _ -> dname == name
                      _ -> False
                  ) (decls st)
  case decl of
    Just (PDecl _ expr) -> return (Just expr)
    _ -> return Nothing

-- | Main function for performing optimization. Takes a list of
-- declarations and returns a list with only the used ones.
findDecl :: Name -> Opti (Maybe Expr)
findDecl name = do
  st <- get
  let decl = find (\d -> case d of
                      PDecl dname _ -> dname == name
                      _ -> False
                  ) (decls st)
  case decl of
    Just (PDecl _ expr) -> return (Just expr)
    _ -> return Nothing

-- | Main function for performing optimization. Takes a list of
-- declarations and returns a list with only the used ones.
findDecl name = do
  st <- get
  let decl = find (\d -> case d of
                      PDecl dname _ -> dname == name
                      _ -> False
                  ) (decls st)
  case decl of
    Just (PDecl _ expr) -> return (Just expr)
    _ -> return Nothing

-- | Main function for performing optimization. Takes a list of
-- declarations and returns a list with only the used ones.