@@ -130,15 +130,15 @@ module _ (f : A → Maybe B) where
130
130
131
131
mapMaybe-concatMap : mapMaybe f ≗ concatMap (fromMaybe ∘ f)
132
132
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
136
136
137
137
length-mapMaybe : ∀ xs → length (mapMaybe f xs) ≤ length xs
138
138
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
142
142
143
143
------------------------------------------------------------------------
144
144
-- _++_
@@ -497,8 +497,8 @@ module _ {P : Pred A p} {f : A → A → A} where
497
497
foldr-forcesᵇ : (∀ x y → P (f x y) → P x × P y) →
498
498
∀ e xs → P (foldr f e xs) → All P xs
499
499
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
502
502
503
503
foldr-preservesᵇ : (∀ {x y} → P x → P y → P (f x y)) →
504
504
∀ {e xs} → P e → All P xs → P (foldr f e xs)
@@ -627,11 +627,10 @@ scanr-defn : ∀ (f : A → B → B) (e : B) →
627
627
scanr f e ≗ map (foldr f e) ∘ tails
628
628
scanr-defn f e [] = refl
629
629
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
635
634
636
635
------------------------------------------------------------------------
637
636
-- scanl
@@ -778,8 +777,7 @@ take++drop (suc n) (x ∷ xs) = cong (x ∷_) (take++drop n xs)
778
777
splitAt-defn : ∀ n → splitAt {A = A} n ≗ < take n , drop n >
779
778
splitAt-defn zero xs = refl
780
779
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)
783
781
784
782
------------------------------------------------------------------------
785
783
-- takeWhile, dropWhile, and span
@@ -805,9 +803,9 @@ module _ {P : Pred A p} (P? : Decidable P) where
805
803
806
804
length-filter : ∀ xs → length (filter P? xs) ≤ length xs
807
805
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
811
809
812
810
filter-all : ∀ {xs} → All P xs → filter P? xs ≡ xs
813
811
filter-all {[]} [] = refl
@@ -819,9 +817,9 @@ module _ {P : Pred A p} (P? : Decidable P) where
819
817
filter-notAll (x ∷ xs) (here ¬px) with P? x
820
818
... | false because _ = s≤s (length-filter xs)
821
819
... | 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
825
823
826
824
filter-some : ∀ {xs} → Any P xs → 0 < length (filter P? xs)
827
825
filter-some {x ∷ xs} (here px) with P? x
@@ -862,9 +860,9 @@ module _ {P : Pred A p} (P? : Decidable P) where
862
860
863
861
filter-++ : ∀ xs ys → filter P? (xs ++ ys) ≡ filter P? xs ++ filter P? ys
864
862
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
868
866
869
867
------------------------------------------------------------------------
870
868
-- derun and deduplicate
@@ -874,9 +872,9 @@ module _ {R : Rel A p} (R? : B.Decidable R) where
874
872
length-derun : ∀ xs → length (derun R? xs) ≤ length xs
875
873
length-derun [] = ≤-refl
876
874
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
880
878
881
879
length-deduplicate : ∀ xs → length (deduplicate R? xs) ≤ length xs
882
880
length-deduplicate [] = z≤n
@@ -905,16 +903,16 @@ module _ {P : Pred A p} (P? : Decidable P) where
905
903
906
904
partition-defn : partition P? ≗ < filter P? , filter (∁? P?) >
907
905
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
911
909
912
910
length-partition : ∀ xs → (let (ys , zs) = partition P? xs) →
913
911
length ys ≤ length xs × length zs ≤ length xs
914
912
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
918
916
919
917
------------------------------------------------------------------------
920
918
-- _ʳ++_
@@ -1063,8 +1061,8 @@ module _ {x y : A} where
1063
1061
1064
1062
∷ʳ-injective : ∀ xs ys → xs ∷ʳ x ≡ ys ∷ʳ y → xs ≡ ys × x ≡ y
1065
1063
∷ʳ-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′)
1068
1066
∷ʳ-injective [] (_ ∷ _ ∷ _) ()
1069
1067
∷ʳ-injective (_ ∷ _ ∷ _) [] ()
1070
1068
0 commit comments