Skip to content

Commit 7e9e14a

Browse files
authored
[ new ] map-concat (#2453)
1 parent a162b5c commit 7e9e14a

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ New modules
3131

3232
Additions to existing modules
3333
-----------------------------
34+
35+
* New lemma in `Data.Vec.Properties`:
36+
```agda
37+
map-concat : map f (concat xss) ≡ concat (map (map f) xss)
38+
```

src/Data/Vec/Properties.agda

+15
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,21 @@ map-⊛ : ∀ (f : A → B → C) (g : A → B) (xs : Vec A n) →
439439
map-⊛ f g [] = refl
440440
map-⊛ f g (x ∷ xs) = cong (f x (g x) ∷_) (map-⊛ f g xs)
441441

442+
map-concat : (f : A B) (xss : Vec (Vec A m) n)
443+
map f (concat xss) ≡ concat (map (map f) xss)
444+
map-concat f [] = refl
445+
map-concat f (xs ∷ xss) = begin
446+
map f (concat (xs ∷ xss))
447+
≡⟨⟩
448+
map f (xs ++ concat xss)
449+
≡⟨ map-++ f xs (concat xss) ⟩
450+
map f xs ++ map f (concat xss)
451+
≡⟨ cong (map f xs ++_) (map-concat f xss) ⟩
452+
map f xs ++ concat (map (map f) xss)
453+
≡⟨⟩
454+
concat (map (map f) (xs ∷ xss))
455+
where open ≡-Reasoning
456+
442457
toList-map : (f : A B) (xs : Vec A n)
443458
toList (map f xs) ≡ List.map f (toList xs)
444459
toList-map f [] = refl

0 commit comments

Comments
 (0)