Debian Codegraph @

src/Data/List/Relation/Binary/Permutation/Setoid/Properties/Maybe.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Properties of permutations using setoid equality (on Maybe elements)
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.List.Relation.Binary.Permutation.Setoid.Properties.Maybe where
10
11 open import Relation.Binary.Core using (_Preserves_⟶_)
12 open import Relation.Binary.Bundles using (Setoid)
13
14 open import Level using (Level)
15 open import Function.Base using (_∘_; _$_)
16
17 open import Data.List.Base using (catMaybes; mapMaybe)
18 open import Data.List.Relation.Binary.Pointwise using (Pointwise; []; _∷_)
19 import Data.List.Relation.Binary.Permutation.Setoid as Permutation
20 open import Data.List.Relation.Binary.Permutation.Setoid.Properties
21
22 open import Data.Maybe using (Maybe; nothing; just)
23 open import Data.Maybe.Relation.Binary.Pointwise using (nothing; just)
24 renaming (setoid to setoidᴹ)
25
26 private
27 variable
28 a b ℓ ℓ′ : Level
29
30 ------------------------------------------------------------------------
31 -- catMaybes
32
33 module _ (sᴬ : Setoid a ℓ) where
34 open Setoid sᴬ using (_≈_)
35 open Permutation sᴬ
36
37 private sᴹ = setoidᴹ sᴬ
38 open Setoid sᴹ using () renaming (_≈_ to _≈ᴹ_)
39 open Permutation sᴹ using () renaming (_↭_ to _↭ᴹ_)
40
41 catMaybes-↭ : ∀ {xs ys} → xs ↭ᴹ ys → catMaybes xs ↭ catMaybes ys
42 catMaybes-↭ (refl p) = refl (pointwise p)
43 where
44 pointwise : ∀ {xs ys} → Pointwise _≈ᴹ_ xs ys →
45 Pointwise _≈_ (catMaybes xs) (catMaybes ys)
46 pointwise [] = []
47 pointwise (just p ∷ ps) = p ∷ pointwise ps
48 pointwise (nothing ∷ ps) = pointwise ps
49 catMaybes-↭ (trans xs↭ ↭ys) = trans (catMaybes-↭ xs↭) (catMaybes-↭ ↭ys)
50 catMaybes-↭ (prep nothing xs↭) = catMaybes-↭ xs↭
51 catMaybes-↭ (prep (just x~y) xs↭) = prep x~y $ catMaybes-↭ xs↭
52 catMaybes-↭ (swap nothing nothing xs↭) = catMaybes-↭ xs↭
53 catMaybes-↭ (swap nothing (just y) xs↭) = prep y $ catMaybes-↭ xs↭
54 catMaybes-↭ (swap (just x) nothing xs↭) = prep x $ catMaybes-↭ xs↭
55 catMaybes-↭ (swap (just x) (just y) xs↭) = swap x y $ catMaybes-↭ xs↭
56
57 ------------------------------------------------------------------------
58 -- mapMaybe
59
60 module _ (sᴬ : Setoid a ℓ) (sᴮ : Setoid b ℓ′) where
61 open Setoid sᴬ using () renaming (_≈_ to _≈ᴬ_)
62 open Permutation sᴬ using () renaming (_↭_ to _↭ᴬ_)
63 open Permutation sᴮ using () renaming (_↭_ to _↭ᴮ_)
64
65 private sᴹᴮ = setoidᴹ sᴮ
66 open Setoid sᴹᴮ using () renaming (_≈_ to _≈ᴹᴮ_)
67
68 mapMaybe-↭ : ∀ {f} → f Preserves _≈ᴬ_ ⟶ _≈ᴹᴮ_ →
69 ∀ {xs ys} → xs ↭ᴬ ys → mapMaybe f xs ↭ᴮ mapMaybe f ys
70 mapMaybe-↭ pres = catMaybes-↭ sᴮ ∘ map⁺ sᴬ sᴹᴮ pres