Skip to content

Commit 0c755fc

Browse files
jamesmckinnaandreasabel
authored andcommitted
Revert "Improve Data.List.Base (fix #2359; deprecate use of with #2123) (#2365)" (#2423)
This reverts commit 438f9ed. Specifically, it restores `with`-based definitions of the `Decidable`-definable functions on `List`s, incl. `filter` Fixes #2415
1 parent 5a4482e commit 0c755fc

File tree

2 files changed

+35
-41
lines changed

2 files changed

+35
-41
lines changed

src/Data/List/Base.agda

+20-26
Original file line numberDiff line numberDiff line change
@@ -358,49 +358,45 @@ removeAt (x ∷ xs) (suc i) = x ∷ removeAt xs i
358358

359359
takeWhile : {P : Pred A p} Decidable P List A List A
360360
takeWhile P? [] = []
361-
takeWhile P? (x ∷ xs) = if does (P? x)
362-
then x ∷ takeWhile P? xs
363-
else []
361+
takeWhile P? (x ∷ xs) with does (P? x)
362+
... | true = x ∷ takeWhile P? xs
363+
... | false = []
364364

365365
takeWhileᵇ : (A Bool) List A List A
366366
takeWhileᵇ p = takeWhile (T? ∘ p)
367367

368368
dropWhile : {P : Pred A p} Decidable P List A List A
369369
dropWhile P? [] = []
370-
dropWhile P? (x ∷ xs) = if does (P? x)
371-
then dropWhile P? xs
372-
else x ∷ xs
370+
dropWhile P? (x ∷ xs) with does (P? x)
371+
... | true = dropWhile P? xs
372+
... | false = x ∷ xs
373373

374374
dropWhileᵇ : (A Bool) List A List A
375375
dropWhileᵇ p = dropWhile (T? ∘ p)
376376

377377
filter : {P : Pred A p} Decidable P List A List A
378378
filter P? [] = []
379-
filter P? (x ∷ xs) =
380-
let xs′ = filter P? xs in
381-
if does (P? x)
382-
then x ∷ xs′
383-
else xs′
379+
filter P? (x ∷ xs) with does (P? x)
380+
... | false = filter P? xs
381+
... | true = x ∷ filter P? xs
384382

385383
filterᵇ : (A Bool) List A List A
386384
filterᵇ p = filter (T? ∘ p)
387385

388386
partition : {P : Pred A p} Decidable P List A (List A × List A)
389-
partition P? [] = [] , []
390-
partition P? (x ∷ xs) =
391-
let ys , zs = partition P? xs in
392-
if does (P? x)
393-
then (x ∷ ys , zs)
394-
else (ys , x ∷ zs)
387+
partition P? [] = ([] , [])
388+
partition P? (x ∷ xs) with does (P? x) | partition P? xs
389+
... | true | (ys , zs) = (x ∷ ys , zs)
390+
... | false | (ys , zs) = (ys , x ∷ zs)
395391

396392
partitionᵇ : (A Bool) List A List A × List A
397393
partitionᵇ p = partition (T? ∘ p)
398394

399395
span : {P : Pred A p} Decidable P List A (List A × List A)
400-
span P? [] = [] , []
401-
span P? ys@(x ∷ xs) = if does (P? x)
402-
then Product.map (x ∷_) id (span P? xs)
403-
else ([] , ys)
396+
span P? [] = ([] , [])
397+
span P? ys@(x ∷ xs) with does (P? x)
398+
... | true = Product.map (x ∷_) id (span P? xs)
399+
... | false = ([] , ys)
404400

405401

406402
spanᵇ : (A Bool) List A List A × List A
@@ -452,11 +448,9 @@ wordsByᵇ p = wordsBy (T? ∘ p)
452448
derun : {R : Rel A p} B.Decidable R List A List A
453449
derun R? [] = []
454450
derun R? (x ∷ []) = x ∷ []
455-
derun R? (x ∷ xs@(y ∷ _)) =
456-
let ys = derun R? xs in
457-
if does (R? x y)
458-
then ys
459-
else x ∷ ys
451+
derun R? (x ∷ xs@(y ∷ _)) with does (R? x y) | derun R? xs
452+
... | true | ys = ys
453+
... | false | ys = x ∷ ys
460454

461455
derunᵇ : (A A Bool) List A List A
462456
derunᵇ r = derun (T? ∘₂ r)

src/Data/List/Properties.agda

+15-15
Original file line numberDiff line numberDiff line change
@@ -1163,13 +1163,13 @@ module _ {P : Pred A p} (P? : Decidable P) where
11631163
filter-all : {xs} All P xs filter P? xs ≡ xs
11641164
filter-all {[]} [] = refl
11651165
filter-all {x ∷ xs} (px ∷ pxs) with P? x
1166-
... | false because [¬px] = contradiction px (invert [¬px])
1167-
... | true because _ = cong (x ∷_) (filter-all pxs)
1166+
... | no ¬px = contradiction px ¬px
1167+
... | true because _ = cong (x ∷_) (filter-all pxs)
11681168

11691169
filter-notAll : xs Any (∁ P) xs length (filter P? xs) < length xs
11701170
filter-notAll (x ∷ xs) (here ¬px) with P? x
1171-
... | false because _ = s≤s (length-filter xs)
1172-
... | true because [px] = contradiction (invert [px]) ¬px
1171+
... | false because _ = s≤s (length-filter xs)
1172+
... | yes px = contradiction px ¬px
11731173
filter-notAll (x ∷ xs) (there any) with ih filter-notAll xs any | does (P? x)
11741174
... | false = m≤n⇒m≤1+n ih
11751175
... | true = s≤s ih
@@ -1185,8 +1185,8 @@ module _ {P : Pred A p} (P? : Decidable P) where
11851185
filter-none : {xs} All (∁ P) xs filter P? xs ≡ []
11861186
filter-none {[]} [] = refl
11871187
filter-none {x ∷ xs} (¬px ∷ ¬pxs) with P? x
1188-
... | false because _ = filter-none ¬pxs
1189-
... | true because [px] = contradiction (invert [px]) ¬px
1188+
... | false because _ = filter-none ¬pxs
1189+
... | yes px = contradiction px ¬px
11901190

11911191
filter-complete : {xs} length (filter P? xs) ≡ length xs
11921192
filter P? xs ≡ xs
@@ -1197,13 +1197,13 @@ module _ {P : Pred A p} (P? : Decidable P) where
11971197

11981198
filter-accept : {x xs} P x filter P? (x ∷ xs) ≡ x ∷ (filter P? xs)
11991199
filter-accept {x} Px with P? x
1200-
... | true because _ = refl
1201-
... | false because [¬Px] = contradiction Px (invert [¬Px])
1200+
... | true because _ = refl
1201+
... | no ¬Px = contradiction Px ¬Px
12021202

12031203
filter-reject : {x xs} ¬ P x filter P? (x ∷ xs) ≡ filter P? xs
12041204
filter-reject {x} ¬Px with P? x
1205-
... | true because [Px] = contradiction (invert [Px]) ¬Px
1206-
... | false because _ = refl
1205+
... | yes Px = contradiction Px ¬Px
1206+
... | false because _ = refl
12071207

12081208
filter-idem : filter P? ∘ filter P? ≗ filter P?
12091209
filter-idem [] = refl
@@ -1241,13 +1241,13 @@ module _ {R : Rel A p} (R? : B.Decidable R) where
12411241

12421242
derun-reject : {x y} xs R x y derun R? (x ∷ y ∷ xs) ≡ derun R? (y ∷ xs)
12431243
derun-reject {x} {y} xs Rxy with R? x y
1244-
... | true because _ = refl
1245-
... | false because [¬Rxy] = contradiction Rxy (invert [¬Rxy])
1244+
... | yes _ = refl
1245+
... | no ¬Rxy = contradiction Rxy ¬Rxy
12461246

12471247
derun-accept : {x y} xs ¬ R x y derun R? (x ∷ y ∷ xs) ≡ x ∷ derun R? (y ∷ xs)
12481248
derun-accept {x} {y} xs ¬Rxy with R? x y
1249-
... | true because [Rxy] = contradiction (invert [Rxy]) ¬Rxy
1250-
... | false because _ = refl
1249+
... | yes Rxy = contradiction Rxy ¬Rxy
1250+
... | no _ = refl
12511251

12521252
------------------------------------------------------------------------
12531253
-- partition
@@ -1260,7 +1260,7 @@ module _ {P : Pred A p} (P? : Decidable P) where
12601260
... | true = cong (Product.map (x ∷_) id) ih
12611261
... | false = cong (Product.map id (x ∷_)) ih
12621262

1263-
length-partition : xs (let ys , zs = partition P? xs)
1263+
length-partition : xs (let (ys , zs) = partition P? xs)
12641264
length ys ≤ length xs × length zs ≤ length xs
12651265
length-partition [] = z≤n , z≤n
12661266
length-partition (x ∷ xs) with ih length-partition xs | does (P? x)

0 commit comments

Comments
 (0)