Debian Codegraph @

src/Data/Maybe/Relation/Unary/All/Properties.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Properties related to All
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.Maybe.Relation.Unary.All.Properties where
10
11 open import Data.Maybe.Base using (Maybe; just; nothing; map; _<∣>_)
12 open import Data.Maybe.Relation.Unary.All as All
13 using (All; nothing; just)
14 open import Data.Maybe.Relation.Binary.Connected
15 using (Connected; just-nothing; nothing-just; nothing; just)
16 open import Data.Product.Base using (_×_; _,_)
17 open import Function.Base using (_∘_)
18 open import Level using (Level)
19 open import Relation.Unary using (Pred; _⊆_)
20 open import Relation.Binary.Core using (Rel)
21
22 private
23 variable
24 a b p q ℓ : Level
25 A : Set a
26 B : Set b
27 P : Pred A p
28 Q : Pred B q
29
30 ------------------------------------------------------------------------
31 -- Relationship with other combinators
32 ------------------------------------------------------------------------
33
34 All⇒Connectedˡ : ∀ {R : Rel A ℓ} {x y} →
35 All (R x) y → Connected R (just x) y
36 All⇒Connectedˡ (just x) = just x
37 All⇒Connectedˡ nothing = just-nothing
38
39 All⇒Connectedʳ : ∀ {R : Rel A ℓ} {x y} →
40 All (λ v → R v y) x → Connected R x (just y)
41 All⇒Connectedʳ (just x) = just x
42 All⇒Connectedʳ nothing = nothing-just
43
44 ------------------------------------------------------------------------
45 -- Introduction (⁺) and elimination (⁻) rules for maybe operations
46 ------------------------------------------------------------------------
47 -- map
48
49 map⁺ : ∀ {f : A → B} {mx} → All (P ∘ f) mx → All P (map f mx)
50 map⁺ (just p) = just p
51 map⁺ nothing = nothing
52
53 map⁻ : ∀ {f : A → B} {mx} → All P (map f mx) → All (P ∘ f) mx
54 map⁻ {mx = just x} (just px) = just px
55 map⁻ {mx = nothing} nothing = nothing
56
57 -- A variant of All.map.
58
59 gmap : ∀ {f : A → B} → P ⊆ Q ∘ f → All P ⊆ All Q ∘ map f
60 gmap g = map⁺ ∘ All.map g
61
62 ------------------------------------------------------------------------
63 -- _<∣>_
64
65 <∣>⁺ : ∀ {mx my} → All P mx → All P my → All P (mx <∣> my)
66 <∣>⁺ (just px) pmy = just px
67 <∣>⁺ nothing pmy = pmy
68
69 <∣>⁻ : ∀ mx {my} → All P (mx <∣> my) → All P mx
70 <∣>⁻ (just x) pmxy = pmxy
71 <∣>⁻ nothing pmxy = nothing