Clean up 'Map' to hide implementation details, extract code
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
32
Utils.agda
Normal file
32
Utils.agda
Normal file
@@ -0,0 +1,32 @@
|
||||
module Utils where
|
||||
|
||||
open import Data.List using (List; []; _∷_; _++_)
|
||||
open import Data.List.Membership.Propositional using (_∈_)
|
||||
open import Data.List.Relation.Unary.All using (All; []; _∷_)
|
||||
open import Data.List.Relation.Unary.Any using (Any; here; there) -- TODO: re-export these with nicer names from map
|
||||
open import Relation.Binary.PropositionalEquality using (_≡_; sym)
|
||||
open import Relation.Nullary using (¬_)
|
||||
|
||||
data Unique {c} {C : Set c} : List C → Set c where
|
||||
empty : Unique []
|
||||
push : ∀ {x : C} {xs : List C}
|
||||
→ All (λ x' → ¬ x ≡ x') xs
|
||||
→ Unique xs
|
||||
→ Unique (x ∷ xs)
|
||||
|
||||
Unique-append : ∀ {c} {C : Set c} {x : C} {xs : List C} →
|
||||
¬ x ∈ xs → Unique xs → Unique (xs ++ (x ∷ []))
|
||||
Unique-append {c} {C} {x} {[]} _ _ = push [] empty
|
||||
Unique-append {c} {C} {x} {x' ∷ xs'} x∉xs (push x'≢ uxs') =
|
||||
push (help x'≢) (Unique-append (λ x∈xs' → x∉xs (there x∈xs')) uxs')
|
||||
where
|
||||
x'≢x : ¬ x' ≡ x
|
||||
x'≢x x'≡x = x∉xs (here (sym x'≡x))
|
||||
|
||||
help : {l : List C} → All (λ x'' → ¬ x' ≡ x'') l → All (λ x'' → ¬ x' ≡ x'') (l ++ (x ∷ []))
|
||||
help {[]} _ = x'≢x ∷ []
|
||||
help {e ∷ es} (x'≢e ∷ x'≢es) = x'≢e ∷ help x'≢es
|
||||
|
||||
All¬-¬Any : ∀ {p c} {C : Set c} {P : C → Set p} {l : List C} → All (λ x → ¬ P x) l → ¬ Any P l
|
||||
All¬-¬Any {l = x ∷ xs} (¬Px ∷ _) (here Px) = ¬Px Px
|
||||
All¬-¬Any {l = x ∷ xs} (_ ∷ ¬Pxs) (there Pxs) = All¬-¬Any ¬Pxs Pxs
|
||||
Reference in New Issue
Block a user