Skip to content

Commit 2839cec

Browse files
Remove some redundant uses of with
2 parents 062ee1b + 621ea0f commit 2839cec

File tree

2 files changed

+34
-38
lines changed

2 files changed

+34
-38
lines changed

src/Algebra/Consequences/Base.agda

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ open import Relation.Binary.Definitions using (Reflexive)
1919
module _ {ℓ} {_•_ : Op₂ A} (_≈_ : Rel A ℓ) where
2020

2121
sel⇒idem : Selective _≈_ _•_ Idempotent _≈_ _•_
22-
sel⇒idem sel x with sel x x
23-
... | inj₁ x•x≈x = x•x≈x
24-
... | inj₂ x•x≈x = x•x≈x
22+
sel⇒idem sel x = reduce (sel x x)
2523

2624
module _ {ℓ} {f : Op₁ A} (_≈_ : Rel A ℓ) where
2725

src/Data/List/Properties.agda

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ module _ (f : A → Maybe B) where
130130

131131
mapMaybe-concatMap : mapMaybe f ≗ concatMap (fromMaybe ∘ f)
132132
mapMaybe-concatMap [] = refl
133-
mapMaybe-concatMap (x ∷ xs) with f x
134-
... | just y = cong (y ∷_) (mapMaybe-concatMap xs)
135-
... | nothing = mapMaybe-concatMap xs
133+
mapMaybe-concatMap (x ∷ xs) with ih mapMaybe-concatMap xs | f x
134+
... | just y = cong (y ∷_) ih
135+
... | nothing = ih
136136

137137
length-mapMaybe : xs length (mapMaybe f xs) ≤ length xs
138138
length-mapMaybe [] = z≤n
139-
length-mapMaybe (x ∷ xs) with f x
140-
... | just y = s≤s (length-mapMaybe xs)
141-
... | nothing = m≤n⇒m≤1+n (length-mapMaybe xs)
139+
length-mapMaybe (x ∷ xs) with ih length-mapMaybe xs | f x
140+
... | just y = s≤s ih
141+
... | nothing = m≤n⇒m≤1+n ih
142142

143143
------------------------------------------------------------------------
144144
-- _++_
@@ -497,8 +497,8 @@ module _ {P : Pred A p} {f : A → A → A} where
497497
foldr-forcesᵇ : ( x y P (f x y) P x × P y)
498498
e xs P (foldr f e xs) All P xs
499499
foldr-forcesᵇ _ _ [] _ = []
500-
foldr-forcesᵇ forces _ (x ∷ xs) Pfold with forces _ _ Pfold
501-
... | (px , pfxs) = px ∷ foldr-forcesᵇ forces _ xs pfxs
500+
foldr-forcesᵇ forces _ (x ∷ xs) Pfold =
501+
let px , pfxs = forces _ _ Pfold in px ∷ foldr-forcesᵇ forces _ xs pfxs
502502

503503
foldr-preservesᵇ : ( {x y} P x P y P (f x y))
504504
{e xs} P e All P xs P (foldr f e xs)
@@ -627,11 +627,10 @@ scanr-defn : ∀ (f : A → B → B) (e : B) →
627627
scanr f e ≗ map (foldr f e) ∘ tails
628628
scanr-defn f e [] = refl
629629
scanr-defn f e (x ∷ []) = refl
630-
scanr-defn f e (x ∷ y ∷ xs)
631-
with scanr f e (y ∷ xs) | scanr-defn f e (y ∷ xs)
632-
... | [] | ()
633-
... | z ∷ zs | eq with ∷-injective eq
634-
... | z≡fy⦇f⦈xs , _ = cong₂ (λ z f x z ∷_) z≡fy⦇f⦈xs eq
630+
scanr-defn f e (x ∷ y∷xs@(_ ∷ _))
631+
with eq scanr-defn f e y∷xs
632+
with z ∷ zs scanr f e y∷xs
633+
= let z≡fy⦇f⦈xs , _ = ∷-injective eq in cong₂ (λ z f x z ∷_) z≡fy⦇f⦈xs eq
635634

636635
------------------------------------------------------------------------
637636
-- scanl
@@ -778,8 +777,7 @@ take++drop (suc n) (x ∷ xs) = cong (x ∷_) (take++drop n xs)
778777
splitAt-defn : n splitAt {A = A} n ≗ < take n , drop n >
779778
splitAt-defn zero xs = refl
780779
splitAt-defn (suc n) [] = refl
781-
splitAt-defn (suc n) (x ∷ xs) with splitAt n xs | splitAt-defn n xs
782-
... | (ys , zs) | ih = cong (Prod.map (x ∷_) id) ih
780+
splitAt-defn (suc n) (x ∷ xs) = cong (Prod.map (x ∷_) id) (splitAt-defn n xs)
783781

784782
------------------------------------------------------------------------
785783
-- takeWhile, dropWhile, and span
@@ -805,9 +803,9 @@ module _ {P : Pred A p} (P? : Decidable P) where
805803

806804
length-filter : xs length (filter P? xs) ≤ length xs
807805
length-filter [] = z≤n
808-
length-filter (x ∷ xs) with does (P? x)
809-
... | false = m≤n⇒m≤1+n (length-filter xs)
810-
... | true = s≤s (length-filter xs)
806+
length-filter (x ∷ xs) with ih length-filter xs | does (P? x)
807+
... | false = m≤n⇒m≤1+n ih
808+
... | true = s≤s ih
811809

812810
filter-all : {xs} All P xs filter P? xs ≡ xs
813811
filter-all {[]} [] = refl
@@ -819,9 +817,9 @@ module _ {P : Pred A p} (P? : Decidable P) where
819817
filter-notAll (x ∷ xs) (here ¬px) with P? x
820818
... | false because _ = s≤s (length-filter xs)
821819
... | yes px = contradiction px ¬px
822-
filter-notAll (x ∷ xs) (there any) with does (P? x)
823-
... | false = m≤n⇒m≤1+n (filter-notAll xs any)
824-
... | true = s≤s (filter-notAll xs any)
820+
filter-notAll (x ∷ xs) (there any) with ih filter-notAll xs any | does (P? x)
821+
... | false = m≤n⇒m≤1+n ih
822+
... | true = s≤s ih
825823

826824
filter-some : {xs} Any P xs 0 < length (filter P? xs)
827825
filter-some {x ∷ xs} (here px) with P? x
@@ -862,9 +860,9 @@ module _ {P : Pred A p} (P? : Decidable P) where
862860

863861
filter-++ : xs ys filter P? (xs ++ ys) ≡ filter P? xs ++ filter P? ys
864862
filter-++ [] ys = refl
865-
filter-++ (x ∷ xs) ys with does (P? x)
866-
... | true = cong (x ∷_) (filter-++ xs ys)
867-
... | false = filter-++ xs ys
863+
filter-++ (x ∷ xs) ys with ih filter-++ xs ys | does (P? x)
864+
... | true = cong (x ∷_) ih
865+
... | false = ih
868866

869867
------------------------------------------------------------------------
870868
-- derun and deduplicate
@@ -874,9 +872,9 @@ module _ {R : Rel A p} (R? : B.Decidable R) where
874872
length-derun : xs length (derun R? xs) ≤ length xs
875873
length-derun [] = ≤-refl
876874
length-derun (x ∷ []) = ≤-refl
877-
length-derun (x ∷ y ∷ xs) with does (R? x y) | length-derun (y ∷ xs)
878-
... | true | r = m≤n⇒m≤1+n r
879-
... | false | r = s≤s r
875+
length-derun (x ∷ y ∷ xs) with ih length-derun (y ∷ xs) | does (R? x y)
876+
... | true = m≤n⇒m≤1+n ih
877+
... | false = s≤s ih
880878

881879
length-deduplicate : xs length (deduplicate R? xs) ≤ length xs
882880
length-deduplicate [] = z≤n
@@ -905,16 +903,16 @@ module _ {P : Pred A p} (P? : Decidable P) where
905903

906904
partition-defn : partition P? ≗ < filter P? , filter (∁? P?) >
907905
partition-defn [] = refl
908-
partition-defn (x ∷ xs) with does (P? x)
909-
... | true = cong (Prod.map (x ∷_) id) (partition-defn xs)
910-
... | false = cong (Prod.map id (x ∷_)) (partition-defn xs)
906+
partition-defn (x ∷ xs) with ih partition-defn xs | does (P? x)
907+
... | true = cong (Prod.map (x ∷_) id) ih
908+
... | false = cong (Prod.map id (x ∷_)) ih
911909

912910
length-partition : xs (let (ys , zs) = partition P? xs)
913911
length ys ≤ length xs × length zs ≤ length xs
914912
length-partition [] = z≤n , z≤n
915-
length-partition (x ∷ xs) with does (P? x) | length-partition xs
916-
... | true | rec = Prod.map s≤s m≤n⇒m≤1+n rec
917-
... | false | rec = Prod.map m≤n⇒m≤1+n s≤s rec
913+
length-partition (x ∷ xs) with ih length-partition xs | does (P? x)
914+
... | true = Prod.map s≤s m≤n⇒m≤1+n ih
915+
... | false = Prod.map m≤n⇒m≤1+n s≤s ih
918916

919917
------------------------------------------------------------------------
920918
-- _ʳ++_
@@ -1063,8 +1061,8 @@ module _ {x y : A} where
10631061

10641062
∷ʳ-injective : xs ys xs ∷ʳ x ≡ ys ∷ʳ y xs ≡ ys × x ≡ y
10651063
∷ʳ-injective [] [] refl = (refl , refl)
1066-
∷ʳ-injective (x ∷ xs) (y ∷ ys) eq with ∷-injective eq
1067-
... | refl , eq′ = Prod.map (cong (x ∷_)) id (∷ʳ-injective xs ys eq′)
1064+
∷ʳ-injective (x ∷ xs) (y ∷ ys) eq with refl , eq′ ∷-injective eq
1065+
= Prod.map (cong (x ∷_)) id (∷ʳ-injective xs ys eq′)
10681066
∷ʳ-injective [] (_ ∷ _ ∷ _) ()
10691067
∷ʳ-injective (_ ∷ _ ∷ _) [] ()
10701068

0 commit comments

Comments
 (0)