-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More list properties about
catMaybes/mapMaybe
- Follow-up to PR #2361 - Ported from my [formal-prelude](https://github.com/omelkonian/formal-prelude/tree/c10fe94876a7378088f2e4cf68d9b18858dcc256)
- Loading branch information
1 parent
c5255d0
commit 6b8cbb2
Showing
5 changed files
with
213 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/Data/List/Relation/Binary/Permutation/Setoid/Properties/Maybe.agda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
------------------------------------------------------------------------ | ||
-- The Agda standard library | ||
-- | ||
-- Properties of permutations using setoid equality (on Maybe elements) | ||
------------------------------------------------------------------------ | ||
|
||
{-# OPTIONS --cubical-compatible --safe #-} | ||
|
||
module Data.List.Relation.Binary.Permutation.Setoid.Properties.Maybe where | ||
|
||
open import Relation.Binary.Core using (_Preserves_⟶_) | ||
open import Relation.Binary.Bundles using (Setoid) | ||
|
||
open import Level using (Level) | ||
open import Function.Base using (_∘_) | ||
|
||
open import Data.List.Base using (catMaybes; mapMaybe) | ||
open import Data.List.Relation.Binary.Pointwise using (Pointwise; []; _∷_) | ||
import Data.List.Relation.Binary.Permutation.Setoid as Permutation | ||
open import Data.List.Relation.Binary.Permutation.Setoid.Properties | ||
|
||
open import Data.Maybe using (Maybe; nothing; just) | ||
open import Data.Maybe.Relation.Binary.Pointwise using (nothing; just) | ||
renaming (setoid to setoidᴹ) | ||
|
||
private | ||
variable | ||
a b ℓ ℓ′ : Level | ||
|
||
------------------------------------------------------------------------ | ||
-- catMaybes | ||
|
||
module _ (sᴬ : Setoid a ℓ) where | ||
open Setoid sᴬ using (_≈_) | ||
open Permutation sᴬ | ||
|
||
private sᴹ = setoidᴹ sᴬ | ||
open Setoid sᴹ using () renaming (_≈_ to _≈ᴹ_) | ||
open Permutation sᴹ using () renaming (_↭_ to _↭ᴹ_) | ||
|
||
catMaybes-↭ : ∀ {xs ys} → xs ↭ᴹ ys → catMaybes xs ↭ catMaybes ys | ||
catMaybes-↭ (refl p) = refl (pointwise p) | ||
where | ||
pointwise : ∀ {xs ys} → Pointwise _≈ᴹ_ xs ys → | ||
Pointwise _≈_ (catMaybes xs) (catMaybes ys) | ||
pointwise [] = [] | ||
pointwise (just p ∷ ps) = p ∷ pointwise ps | ||
pointwise (nothing ∷ ps) = pointwise ps | ||
catMaybes-↭ (trans xs↭ ↭ys) = trans (catMaybes-↭ xs↭) (catMaybes-↭ ↭ys) | ||
catMaybes-↭ (prep p xs↭) with ih ← catMaybes-↭ xs↭ | p | ||
... | nothing = ih | ||
... | just x~y = prep x~y ih | ||
catMaybes-↭ (swap p q xs↭) with ih ← catMaybes-↭ xs↭ | p | q | ||
... | nothing | nothing = ih | ||
... | nothing | just y = prep y ih | ||
... | just x | nothing = prep x ih | ||
... | just x | just y = swap x y ih | ||
|
||
------------------------------------------------------------------------ | ||
-- mapMaybe | ||
|
||
module _ (sᴬ : Setoid a ℓ) (sᴮ : Setoid b ℓ′) where | ||
open Setoid sᴬ using () renaming (_≈_ to _≈ᴬ_) | ||
open Permutation sᴬ using () renaming (_↭_ to _↭ᴬ_) | ||
open Permutation sᴮ using () renaming (_↭_ to _↭ᴮ_) | ||
|
||
private sᴹᴮ = setoidᴹ sᴮ | ||
open Setoid sᴹᴮ using () renaming (_≈_ to _≈ᴹᴮ_) | ||
|
||
mapMaybe-↭ : | ||
∀ {f} → f Preserves _≈ᴬ_ ⟶ _≈ᴹᴮ_ → | ||
∀ {xs ys} → xs ↭ᴬ ys → mapMaybe f xs ↭ᴮ mapMaybe f ys | ||
mapMaybe-↭ pres = catMaybes-↭ sᴮ ∘ map⁺ sᴬ sᴹᴮ pres |