@@ -31,6 +31,9 @@ private
31
31
a b p q r ℓ : Level
32
32
A : Set a
33
33
B : Set b
34
+ P Q R : Pred A p
35
+ x : A
36
+ xs : List A
34
37
35
38
------------------------------------------------------------------------
36
39
-- Definitions
@@ -67,89 +70,77 @@ Null = All (λ _ → ⊥)
67
70
------------------------------------------------------------------------
68
71
-- Operations on All
69
72
70
- module _ {P : Pred A p} where
73
+ uncons : All P (x ∷ xs) → P x × All P xs
74
+ uncons (px ∷ pxs) = px , pxs
71
75
72
- uncons : ∀ {x xs} → All P (x ∷ xs) → P x × All P xs
73
- uncons (px ∷ pxs) = px , pxs
76
+ head : All P (x ∷ xs) → P x
77
+ head = proj₁ ∘ uncons
74
78
75
- head : ∀ {x xs} → All P (x ∷ xs) → P x
76
- head = proj₁ ∘ uncons
79
+ tail : All P (x ∷ xs) → All P xs
80
+ tail = proj₂ ∘ uncons
77
81
78
- tail : ∀ {x xs} → All P (x ∷ xs) → All P xs
79
- tail = proj₂ ∘ uncons
82
+ reduce : (f : ∀ {x} → P x → B) → All P xs → List B
83
+ reduce f [] = []
84
+ reduce f (px ∷ pxs) = f px ∷ reduce f pxs
80
85
81
- reduce : (f : ∀ {x} → P x → B) → ∀ {xs} → All P xs → List B
82
- reduce f [] = []
83
- reduce f (px ∷ pxs ) = f px ∷ reduce f pxs
86
+ construct : (f : B → ∃ P) (xs : List B) → ∃ ( All P)
87
+ construct f [] = [] , []
88
+ construct f (x ∷ xs ) = Prod.zip _∷_ _∷_ (f x) (construct f xs)
84
89
85
- construct : (f : B → ∃ P) (xs : List B ) → ∃ ( All P)
86
- construct f [] = [] , []
87
- construct f (x ∷ xs ) = Prod.zip _∷_ _∷_ (f x) (construct f xs)
90
+ fromList : (xs : List ( ∃ P)) → All P (List.map proj₁ xs )
91
+ fromList [] = []
92
+ fromList ((x , p) ∷ xps ) = p ∷ fromList xps
88
93
89
- fromList : (xs : List (∃ P)) → All P (List.map proj₁ xs)
90
- fromList [] = []
91
- fromList ((x , p) ∷ xps) = p ∷ fromList xps
94
+ toList : All P xs → List (∃ P)
95
+ toList pxs = reduce (λ {x} px → x , px) pxs
92
96
93
- toList : ∀ {xs} → All P xs → List (∃ P)
94
- toList pxs = reduce (λ {x} px → x , px) pxs
97
+ map : P ⊆ Q → All P ⊆ All Q
98
+ map g [] = []
99
+ map g (px ∷ pxs) = g px ∷ map g pxs
95
100
96
- module _ {P : Pred A p} {Q : Pred A q} where
101
+ zipWith : P ∩ Q ⊆ R → All P ∩ All Q ⊆ All R
102
+ zipWith f ([] , []) = []
103
+ zipWith f (px ∷ pxs , qx ∷ qxs) = f (px , qx) ∷ zipWith f (pxs , qxs)
97
104
98
- map : P ⊆ Q → All P ⊆ All Q
99
- map g [] = []
100
- map g (px ∷ pxs ) = g px ∷ map g pxs
105
+ unzipWith : R ⊆ P ∩ Q → All R ⊆ All P ∩ All Q
106
+ unzipWith f [] = [] , []
107
+ unzipWith f (rx ∷ rxs ) = Prod.zip _∷_ _∷_ (f rx) (unzipWith f rxs)
101
108
102
- module _ {P : Pred A p} {Q : Pred A q} {R : Pred A r} where
109
+ zip : All P ∩ All Q ⊆ All (P ∩ Q)
110
+ zip = zipWith id
103
111
104
- zipWith : P ∩ Q ⊆ R → All P ∩ All Q ⊆ All R
105
- zipWith f ([] , []) = []
106
- zipWith f (px ∷ pxs , qx ∷ qxs) = f (px , qx) ∷ zipWith f (pxs , qxs)
107
-
108
- unzipWith : R ⊆ P ∩ Q → All R ⊆ All P ∩ All Q
109
- unzipWith f [] = [] , []
110
- unzipWith f (rx ∷ rxs) = Prod.zip _∷_ _∷_ (f rx) (unzipWith f rxs)
111
-
112
- module _ {P : Pred A p} {Q : Pred A q} where
113
-
114
- zip : All P ∩ All Q ⊆ All (P ∩ Q)
115
- zip = zipWith id
116
-
117
- unzip : All (P ∩ Q) ⊆ All P ∩ All Q
118
- unzip = unzipWith id
112
+ unzip : All (P ∩ Q) ⊆ All P ∩ All Q
113
+ unzip = unzipWith id
119
114
120
115
module _ (S : Setoid a ℓ) {P : Pred (Setoid.Carrier S) p} where
121
116
open Setoid S renaming (Carrier to C; refl to refl₁)
122
117
open SetoidMembership S
123
118
124
- tabulateₛ : ∀ {xs} → (∀ {x} → x ∈ xs → P x) → All P xs
119
+ tabulateₛ : (∀ {x} → x ∈ xs → P x) → All P xs
125
120
tabulateₛ {[]} hyp = []
126
121
tabulateₛ {x ∷ xs} hyp = hyp (here refl₁) ∷ tabulateₛ (hyp ∘ there)
127
122
128
- module _ {P : Pred A p} where
129
-
130
- tabulate : ∀ {xs} → (∀ {x} → x ∈ₚ xs → P x) → All P xs
131
- tabulate = tabulateₛ (P.setoid A)
123
+ tabulate : (∀ {x} → x ∈ₚ xs → P x) → All P xs
124
+ tabulate = tabulateₛ (P.setoid _)
132
125
133
126
self : ∀ {xs : List A} → All (const A) xs
134
127
self = tabulate (λ {x} _ → x)
135
128
136
129
------------------------------------------------------------------------
137
130
-- (weak) updateAt
138
131
139
- module _ {P : Pred A p} where
140
-
141
- infixl 6 _[_]%=_ _[_]≔_
132
+ infixl 6 _[_]%=_ _[_]≔_
142
133
143
- updateAt : ∀ {x xs} → x ∈ₚ xs → (P x → P x) → All P xs → All P xs
144
- updateAt () f []
145
- updateAt (here refl) f (px ∷ pxs) = f px ∷ pxs
146
- updateAt (there i) f (px ∷ pxs) = px ∷ updateAt i f pxs
134
+ updateAt : x ∈ₚ xs → (P x → P x) → All P xs → All P xs
135
+ updateAt () f []
136
+ updateAt (here refl) f (px ∷ pxs) = f px ∷ pxs
137
+ updateAt (there i) f (px ∷ pxs) = px ∷ updateAt i f pxs
147
138
148
- _[_]%=_ : ∀ {x xs} → All P xs → x ∈ₚ xs → (P x → P x) → All P xs
149
- pxs [ i ]%= f = updateAt i f pxs
139
+ _[_]%=_ : All P xs → x ∈ₚ xs → (P x → P x) → All P xs
140
+ pxs [ i ]%= f = updateAt i f pxs
150
141
151
- _[_]≔_ : ∀ {x xs} → All P xs → x ∈ₚ xs → P x → All P xs
152
- pxs [ i ]≔ px = pxs [ i ]%= const px
142
+ _[_]≔_ : All P xs → x ∈ₚ xs → P x → All P xs
143
+ pxs [ i ]≔ px = pxs [ i ]%= const px
153
144
154
145
------------------------------------------------------------------------
155
146
-- Traversable-like functions
@@ -168,7 +159,7 @@ module _ (p : Level) {A : Set a} {P : Pred A (a ⊔ p)}
168
159
mapA : ∀ {Q : Pred A q} → (Q ⊆ F ∘′ P) → All Q ⊆ (F ∘′ All P)
169
160
mapA f = sequenceA ∘′ map f
170
161
171
- forA : ∀ {Q : Pred A q} {xs} → All Q xs → (Q ⊆ F ∘′ P) → F (All P xs)
162
+ forA : ∀ {Q : Pred A q} → All Q xs → (Q ⊆ F ∘′ P) → F (All P xs)
172
163
forA qxs f = mapA f qxs
173
164
174
165
module _ (p : Level) {A : Set a} {P : Pred A (a ⊔ p)}
@@ -184,56 +175,56 @@ module _ (p : Level) {A : Set a} {P : Pred A (a ⊔ p)}
184
175
mapM : ∀ {Q : Pred A q} → (Q ⊆ M ∘′ P) → All Q ⊆ (M ∘′ All P)
185
176
mapM = mapA p App
186
177
187
- forM : ∀ {Q : Pred A q} {xs} → All Q xs → (Q ⊆ M ∘′ P) → M (All P xs)
178
+ forM : ∀ {Q : Pred A q} → All Q xs → (Q ⊆ M ∘′ P) → M (All P xs)
188
179
forM = forA p App
189
180
190
181
------------------------------------------------------------------------
191
182
-- Generalised lookup based on a proof of Any
192
183
193
- module _ {P : Pred A p} {Q : Pred A q} where
194
-
195
- lookupAny : ∀ {xs} → All P xs → (i : Any Q xs) → (P ∩ Q) (Any.lookup i)
196
- lookupAny (px ∷ pxs) (here qx) = px , qx
197
- lookupAny (px ∷ pxs) (there i) = lookupAny pxs i
184
+ lookupAny : All P xs → (i : Any Q xs) → (P ∩ Q) (Any.lookup i)
185
+ lookupAny (px ∷ pxs) (here qx) = px , qx
186
+ lookupAny (px ∷ pxs) (there i) = lookupAny pxs i
198
187
199
- module _ {P : Pred A p} {Q : Pred A q} {R : Pred A r} where
188
+ lookupWith : ∀[ P ⇒ Q ⇒ R ] → All P xs → (i : Any Q xs) → R (Any.lookup i)
189
+ lookupWith f pxs i = Prod.uncurry f (lookupAny pxs i)
200
190
201
- lookupWith : ∀[ P ⇒ Q ⇒ R ] → ∀ {xs} → All P xs → (i : Any Q xs) →
202
- R (Any.lookup i)
203
- lookupWith f pxs i = Prod.uncurry f (lookupAny pxs i)
204
-
205
- module _ {P : Pred A p} where
206
-
207
- lookup : ∀ {xs} → All P xs → (∀ {x} → x ∈ₚ xs → P x)
208
- lookup pxs = lookupWith (λ { px refl → px }) pxs
191
+ lookup : All P xs → (∀ {x} → x ∈ₚ xs → P x)
192
+ lookup pxs = lookupWith (λ { px refl → px }) pxs
209
193
210
194
module _ (S : Setoid a ℓ) {P : Pred (Setoid.Carrier S) p} where
211
195
open Setoid S renaming (sym to sym₁)
212
196
open SetoidMembership S
213
197
214
- lookupₛ : ∀ {xs} → P Respects _≈_ → All P xs → (∀ {x} → x ∈ xs → P x)
198
+ lookupₛ : P Respects _≈_ → All P xs → (∀ {x} → x ∈ xs → P x)
215
199
lookupₛ resp pxs = lookupWith (λ py x=y → resp (sym₁ x=y) py) pxs
216
200
217
201
------------------------------------------------------------------------
218
202
-- Properties of predicates preserved by All
219
203
220
- module _ {P : Pred A p} where
204
+ all? : Decidable P → Decidable (All P)
205
+ all? p [] = yes []
206
+ all? p (x ∷ xs) = Dec.map′ (uncurry _∷_) uncons (p x ×-dec all? p xs)
207
+
208
+ universal : Universal P → Universal (All P)
209
+ universal u [] = []
210
+ universal u (x ∷ xs) = u x ∷ universal u xs
221
211
222
- all? : Decidable P → Decidable (All P)
223
- all? p [] = yes []
224
- all? p (x ∷ xs) = Dec.map′ (uncurry _∷_) uncons (p x ×-dec all? p xs)
212
+ irrelevant : Irrelevant P → Irrelevant (All P)
213
+ irrelevant irr [] [] = P.refl
214
+ irrelevant irr (px₁ ∷ pxs₁) (px₂ ∷ pxs₂) =
215
+ P.cong₂ _∷_ (irr px₁ px₂) (irrelevant irr pxs₁ pxs₂)
225
216
226
- universal : Universal P → Universal (All P)
227
- universal u [] = []
228
- universal u (x ∷ xs) = u x ∷ universal u xs
217
+ satisfiable : Satisfiable (All P)
218
+ satisfiable = [] , []
229
219
230
- irrelevant : Irrelevant P → Irrelevant (All P)
231
- irrelevant irr [] [] = P.refl
232
- irrelevant irr (px₁ ∷ pxs₁) (px₂ ∷ pxs₂) =
233
- P.cong₂ _∷_ (irr px₁ px₂) (irrelevant irr pxs₁ pxs₂)
234
220
235
- satisfiable : Satisfiable (All P)
236
- satisfiable = [] , []
221
+ ------------------------------------------------------------------------
222
+ -- DEPRECATED
223
+ ------------------------------------------------------------------------
224
+ -- Please use the new names as continuing support for the old names is
225
+ -- not guaranteed.
226
+
227
+ -- Version 1.4
237
228
238
229
all = all?
239
230
{-# WARNING_ON_USAGE all
0 commit comments