Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRY] refactor #2479 #2485

Merged
merged 2 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ Additions to existing modules
∈-concatMap⁻ : y ∈ concatMap f xs → Any ((y ∈_) ∘ f) xs
++-∈⇔ : v ∈ xs ++ ys ⇔ (v ∈ xs ⊎ v ∈ ys)
[]∉map∷ : [] ∉ map (x ∷_) xss
map∷⁻ : xs ∈ map (y ∷_) xss → ∃[ ys ] ys ∈ xss × xs ≡ y ∷ ys
map∷-decomp∈ : (x ∷ xs) ∈ map (y ∷_) xss → x ≡ y × xs ∈ xss
map∷-decomp : xs ∈ map (y ∷_) xss → ∃[ ys ] ys ∈ xss × y ∷ ys ≡ xs
∈-map∷⁻ : xs ∈ map (x ∷_) xss → x ∈ xs
∉[] : x ∉ []
deduplicate-∈⇔ : z ∈ xs ⇔ z ∈ deduplicate _≈?_ xs
Expand Down
20 changes: 6 additions & 14 deletions src/Data/List/Membership/Propositional/Properties.agda
Original file line number Diff line number Diff line change
Expand Up @@ -454,22 +454,14 @@ module _ {R : A → A → Set ℓ} where
------------------------------------------------------------------------
-- nested lists

map∷⁻ : xs ∈ map (y ∷_) xss → ∃[ ys ] ys ∈ xss × xs ≡ y ∷ ys
map∷⁻ = ∈-map⁻ (_ ∷_)

[]∉map∷ : (List A ∋ []) ∉ map (x ∷_) xss
[]∉map∷ {xss = _ ∷ _} (there p) = []∉map∷ p
[]∉map∷ p with () ← map∷ p

map∷-decomp∈ : (List A ∋ x ∷ xs) ∈ map (y ∷_) xss → x ≡ y × xs ∈ xss
map∷-decomp∈ {xss = _ ∷ _} = λ where
(here refl) → refl , here refl
(there p) → map₂ there $ map∷-decomp∈ p

map∷-decomp : xs ∈ map (y ∷_) xss → ∃[ ys ] ys ∈ xss × y ∷ ys ≡ xs
map∷-decomp {xss = _ ∷ _} (here refl) = -, here refl , refl
map∷-decomp {xs = []} {xss = _ ∷ _} (there xs∈) = contradiction xs∈ []∉map∷
map∷-decomp {xs = x ∷ xs} {xss = _ ∷ _} (there xs∈) =
let eq , p = map∷-decomp∈ xs∈
in -, there p , cong (_∷ _) (sym eq)
map∷-decomp∈ p with _ , xs∈xss , refl ← map∷⁻ p = refl , xs∈xss

∈-map∷⁻ : xs ∈ map (x ∷_) xss → x ∈ xs
∈-map∷⁻ {xss = _ ∷ _} = λ where
(here refl) → here refl
(there p) → ∈-map∷⁻ p
∈-map∷⁻ p with _ , _ , refl ← map∷⁻ p = here refl