@@ -21,7 +21,7 @@ open import Data.List.Base as List
21
21
open import Data.List.Membership.Propositional using (_∈_)
22
22
open import Data.List.Relation.Unary.All using (All; []; _∷_)
23
23
open import Data.List.Relation.Unary.Any using (Any; here; there)
24
- open import Data.Maybe.Base using (Maybe; just; nothing)
24
+ open import Data.Maybe.Base as Maybe using (Maybe; just; nothing)
25
25
open import Data.Nat.Base
26
26
open import Data.Nat.Divisibility
27
27
open import Data.Nat.Properties
@@ -44,6 +44,7 @@ open import Relation.Nullary.Decidable as Decidable using (isYes; map′; ⌊_
44
44
open import Relation.Unary using (Pred; Decidable; ∁)
45
45
open import Relation.Unary.Properties using (∁?)
46
46
47
+
47
48
open ≡-Reasoning
48
49
49
50
private
@@ -761,6 +762,12 @@ length-take zero xs = refl
761
762
length-take (suc n) [] = refl
762
763
length-take (suc n) (x ∷ xs) = cong suc (length-take n xs)
763
764
765
+ -- Take commutes with map.
766
+ take-map : ∀ {f : A → B} (n : ℕ) xs → take n (map f xs) ≡ map f (take n xs)
767
+ take-map zero xs = refl
768
+ take-map (suc s) [] = refl
769
+ take-map (suc s) (a ∷ xs) = cong (_ ∷_) (take-map s xs)
770
+
764
771
take-suc : (xs : List A) (i : Fin (length xs)) → let m = toℕ i in
765
772
take (suc m) xs ≡ take m xs ∷ʳ lookup xs i
766
773
take-suc (x ∷ xs) zero = refl
@@ -791,12 +798,17 @@ length-drop zero xs = refl
791
798
length-drop (suc n) [] = refl
792
799
length-drop (suc n) (x ∷ xs) = length-drop n xs
793
800
801
+ -- Drop commutes with map.
802
+ drop-map : ∀ {f : A → B} (n : ℕ) xs → drop n (map f xs) ≡ map f (drop n xs)
803
+ drop-map zero xs = refl
804
+ drop-map (suc n) [] = refl
805
+ drop-map (suc n) (a ∷ xs) = drop-map n xs
806
+
794
807
-- Dropping from an empty list does nothing.
795
808
drop-[] : ∀ m → drop {A = A} m [] ≡ []
796
809
drop-[] zero = refl
797
810
drop-[] (suc m) = refl
798
811
799
-
800
812
take++drop : ∀ n (xs : List A) → take n xs ++ drop n xs ≡ xs
801
813
take++drop zero xs = refl
802
814
take++drop (suc n) [] = refl
@@ -1118,6 +1130,17 @@ module _ {x y : A} where
1118
1130
1119
1131
1120
1132
1133
+ ------------------------------------------------------------------------
1134
+ -- head
1135
+
1136
+ -- 'commute' List.head and List.map to obtain a Maybe.map and List.head.
1137
+ head-map : ∀ {f : A → B} xs → head (map f xs) ≡ Maybe.map f (head xs)
1138
+ head-map [] = refl
1139
+ head-map (_ ∷ _) = refl
1140
+
1141
+
1142
+
1143
+
1121
1144
------------------------------------------------------------------------
1122
1145
-- DEPRECATED
1123
1146
------------------------------------------------------------------------
0 commit comments