12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667-------------------------------------------------------------------------- The Agda standard library---- Lifting a relation such that `nothing` is also related to `just`------------------------------------------------------------------------ {-# OPTIONS --cubical-compatible --safe #-} module Data.Maybe.Relation.Binary.Connected where open import Levelopen import Data.Maybe.Base using (Maybe; just; nothing)open import Function.Bundles using (_⇔_; mk⇔)open import Relation.Binary.Core using (REL; _⇒_)open import Relation.Binary.Definitions using (Reflexive; Sym; Decidable)open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)open import Relation.Nullaryimport Relation.Nullary.Decidable as Dec private variable a b ℓ : Level A : Set a B : Set b R S T : REL A B ℓ x y : A -------------------------------------------------------------------------- Definition data Connected {A : Set a} {B : Set b} (R : REL A B ℓ) : REL (Maybe A) (Maybe B) (a ⊔ b ⊔ ℓ) where just : R x y → Connected R (just x) (just y) just-nothing : Connected R (just x) nothing nothing-just : Connected R nothing (just y) nothing : Connected R nothing nothing -------------------------------------------------------------------------- Properties drop-just : Connected R (just x) (just y) → R x ydrop-just (just p) = p just-equivalence : R x y ⇔ Connected R (just x) (just y)just-equivalence = mk⇔ just drop-just -------------------------------------------------------------------------- Relational properties refl : Reflexive R → Reflexive (Connected R)refl R-refl {just _} = just R-reflrefl R-refl {nothing} = nothing reflexive : _≡_ ⇒ R → _≡_ ⇒ Connected Rreflexive reflexive ≡.refl = refl (reflexive ≡.refl) sym : Sym R S → Sym (Connected R) (Connected S)sym R-sym (just p) = just (R-sym p)sym R-sym nothing-just = just-nothingsym R-sym just-nothing = nothing-justsym R-sym nothing = nothing connected? : Decidable R → Decidable (Connected R)connected? R? (just x) (just y) = Dec.map just-equivalence (R? x y)connected? R? (just x) nothing = yes just-nothingconnected? R? nothing (just y) = yes nothing-justconnected? R? nothing nothing = yes nothing