Skip to content

Commit abbd3e7

Browse files
gallaisMatthewDaggitt
authored andcommitted
[ refactor ] more general version of _--_ et al. (#598)
1 parent f8f356f commit abbd3e7

File tree

4 files changed

+53
-19
lines changed

4 files changed

+53
-19
lines changed

CHANGELOG.md

+20-6
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ Non-backwards compatible changes
288288
* The proofs `toList⁺` and `toList⁻` in `Data.Vec.Relation.Unary.All.Properties` have been swapped
289289
as they were the opposite way round to similar properties in the rest of the library.
290290

291+
* The functions `_∷=_` and `_─_` have been removed from `Data.List.Membership.Setoid` as they are subsumed by the more general versions now part of `Data.List.Any`.
292+
291293
* Changed the type of `≡-≟-identity` to make use of the fact that equality
292294
being decidable implies UIP.
293295

@@ -654,14 +656,11 @@ Other minor additions
654656
forM : All Q xs → (Q ⊆ M ∘′ P) → M (All P xs)
655657
```
656658

657-
* Added new operators to `Data.List.Base`:
659+
* Added new proofs to `Data.List.Relation.Unary.All.Properties`:
658660
```agda
659-
_[_]%=_ : (xs : List A) → Fin (length xs) → (A → A) → List A
660-
_[_]∷=_ : (xs : List A) → Fin (length xs) → A → List A
661-
_─_ : (xs : List A) → Fin (length xs) → List A
662-
663-
reverseAcc : List A → List A → List A
661+
respects : P Respects _≈_ → (All P) Respects _≋_
664662
```
663+
665664
A generalization of single point overwrite `_[_]≔_`
666665
to single-point modification `_[_]%=_`
667666
(alias with different argument order: `updateAt`):
@@ -678,13 +677,28 @@ Other minor additions
678677
* Added new proofs to `Data.List.Relation.Unary.All.Properties`:
679678
```agda
680679
respects : P Respects _≈_ → (All P) Respects _≋_
680+
─⁺ : All Q xs → All Q (xs Any.─ p)
681+
─⁻ : Q (Any.lookup p) → All Q (xs Any.─ p) → All Q xs
682+
```
683+
684+
* Added new functions to `Data.List.Relation.Unary.Any`:
685+
```agda
686+
lookup : Any P xs → A
687+
_∷=_ : Any P xs → A → List A
688+
_─_ : ∀ xs → Any P xs → List A
681689
```
682690

683691
* Added new functions to `Data.List.Base`:
684692
```agda
685693
intercalate : List A → List (List A) → List A
686694
partitionSumsWith : (A → B ⊎ C) → List A → List B × List C
687695
partitionSums : List (A ⊎ B) → List A × List B
696+
697+
_[_]%=_ : (xs : List A) → Fin (length xs) → (A → A) → List A
698+
_[_]∷=_ : (xs : List A) → Fin (length xs) → A → List A
699+
_─_ : (xs : List A) → Fin (length xs) → List A
700+
701+
reverseAcc : List A → List A → List A
688702
```
689703

690704
* Added new proofs to `Data.List.Membership.Propositional.Properties`:

src/Data/List/Membership/Setoid.agda

+3-8
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ module Data.List.Membership.Setoid {c ℓ} (S : Setoid c ℓ) where
1313
open import Function using (_∘_; id; flip)
1414
open import Data.Fin using (Fin; zero; suc)
1515
open import Data.List.Base as List using (List; []; _∷_; length; lookup)
16-
open import Data.List.Relation.Unary.Any as Any
16+
open import Data.List.Relation.Unary.Any
1717
using (Any; index; map; here; there)
1818
open import Data.Product as Prod using (∃; _×_; _,_)
1919
open import Relation.Unary using (Pred)
2020
open import Relation.Nullary using (¬_)
2121

2222
open Setoid S renaming (Carrier to A)
2323

24+
open Data.List.Relation.Unary.Any using (_∷=_; _─_) public
25+
2426
------------------------------------------------------------------------
2527
-- Definitions
2628

@@ -40,13 +42,6 @@ mapWith∈ : ∀ {b} {B : Set b}
4042
mapWith∈ [] f = []
4143
mapWith∈ (x ∷ xs) f = f (here refl) ∷ mapWith∈ xs (f ∘ there)
4244

43-
_∷=_ : {xs x} x ∈ xs A List A
44-
_∷=_ {xs} x∈xs v = xs List.[ index x∈xs ]∷= v
45-
46-
infixl 4 _─_
47-
_─_ : xs {x} x ∈ xs List A
48-
xs ─ x∈xs = xs List.─ index x∈xs
49-
5045
------------------------------------------------------------------------
5146
-- Finding and losing witnesses
5247

src/Data/List/Relation/Unary/All/Properties.agda

+14-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ open import Data.Fin using (Fin) renaming (zero to fzero; suc to fsuc)
1515
open import Data.List.Base
1616
open import Data.List.Membership.Propositional
1717
open import Data.List.Relation.Unary.All as All using (All; []; _∷_)
18-
open import Data.List.Relation.Unary.Any using (Any; here; there)
18+
open import Data.List.Relation.Unary.Any as Any using (Any; here; there)
1919
import Data.List.Relation.Binary.Equality.Setoid as ListEq using (_≋_; []; _∷_)
2020
open import Data.List.Relation.Binary.Pointwise using (Pointwise; []; _∷_)
2121
open import Data.List.Relation.Binary.Subset.Propositional using (_⊆_)
@@ -217,6 +217,19 @@ module _ {a p} {A : Set a} {P : A → Set p} where
217217
tabulate⁻ {suc n} (px ∷ _) fzero = px
218218
tabulate⁻ {suc n} (_ ∷ pf) (fsuc i) = tabulate⁻ pf i
219219

220+
------------------------------------------------------------------------
221+
-- remove
222+
223+
module _ {a p q} {A : Set a} {P : A Set p} {Q : A Set q} where
224+
225+
─⁺ : {xs} (p : Any P xs) All Q xs All Q (xs Any.─ p)
226+
─⁺ (here px) (_ ∷ qs) = qs
227+
─⁺ (there p) (q ∷ qs) = q ∷ ─⁺ p qs
228+
229+
─⁻ : {xs} (p : Any P xs) Q (Any.lookup p) All Q (xs Any.─ p) All Q xs
230+
─⁻ (here px) q qs = q ∷ qs
231+
─⁻ (there p) q (q′ ∷ qs) = q′ ∷ ─⁻ p q qs
232+
220233
------------------------------------------------------------------------
221234
-- filter
222235

src/Data/List/Relation/Unary/Any.agda

+16-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,22 @@ map : ∀ {p q} {P : A → Set p} {Q : A → Set q} → P ⊆ Q → Any P ⊆ An
4343
map g (here px) = here (g px)
4444
map g (there pxs) = there (map g pxs)
4545

46-
-- `index x∈xs` is the list position (zero-based) which `x∈xs` points to.
47-
index : {p} {P : A Set p} {xs} Any P xs Fin (List.length xs)
48-
index (here px) = zero
49-
index (there pxs) = suc (index pxs)
46+
module _ {p} {P : A Set p} where
47+
48+
-- `index x∈xs` is the list position (zero-based) which `x∈xs` points to.
49+
index : {xs} Any P xs Fin (List.length xs)
50+
index (here px) = zero
51+
index (there pxs) = suc (index pxs)
52+
53+
lookup : {xs} Any P xs A
54+
lookup {xs} p = List.lookup xs (index p)
55+
56+
_∷=_ : {xs} Any P xs A List A
57+
_∷=_ {xs} x∈xs v = xs List.[ index x∈xs ]∷= v
58+
59+
infixl 4 _─_
60+
_─_ : xs Any P xs List A
61+
xs ─ x∈xs = xs List.─ index x∈xs
5062

5163
-- If any element satisfies P, then P is satisfied.
5264
satisfied : {p} {P : A Set p} {xs} Any P xs ∃ P

0 commit comments

Comments
 (0)