| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- An inductive definition of the heterogeneous infix relation |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.List.Relation.Binary.Infix.Heterogeneous where |
| 10 |
|
| 11 |
open import Level using (Level; _⊔_) |
| 12 |
open import Relation.Binary.Core using (REL; _⇒_) |
| 13 |
open import Data.List.Base as List using (List; []; _∷_; _++_) |
| 14 |
open import Data.List.Relation.Binary.Pointwise |
| 15 |
using (Pointwise) |
| 16 |
open import Data.List.Relation.Binary.Prefix.Heterogeneous as Prefix |
| 17 |
using (Prefix; []; _∷_; _++ᵖ_) |
| 18 |
|
| 19 |
private |
| 20 |
variable |
| 21 |
a b r s : Level |
| 22 |
A : Set a |
| 23 |
B : Set b |
| 24 |
R : REL A B r |
| 25 |
S : REL A B s |
| 26 |
|
| 27 |
module _ {A : Set a} {B : Set b} (R : REL A B r) where |
| 28 |
|
| 29 |
data Infix : REL (List A) (List B) (a ⊔ b ⊔ r) where |
| 30 |
here : ∀ {as bs} → Prefix R as bs → Infix as bs |
| 31 |
there : ∀ {b as bs} → Infix as bs → Infix as (b ∷ bs) |
| 32 |
|
| 33 |
data View (as : List A) : List B → Set (a ⊔ b ⊔ r) where |
| 34 |
MkView : ∀ pref {inf} → Pointwise R as inf → ∀ suff → |
| 35 |
View as (pref List.++ inf List.++ suff) |
| 36 |
|
| 37 |
infixr 5 _++ⁱ_ _ⁱ++_ |
| 38 |
|
| 39 |
_++ⁱ_ : ∀ xs {as bs} → Infix R as bs → Infix R as (xs ++ bs) |
| 40 |
[] ++ⁱ rs = rs |
| 41 |
(x ∷ xs) ++ⁱ rs = there (xs ++ⁱ rs) |
| 42 |
|
| 43 |
_ⁱ++_ : ∀ {as bs} → Infix R as bs → ∀ xs → Infix R as (bs ++ xs) |
| 44 |
here rs ⁱ++ xs = here (rs ++ᵖ xs) |
| 45 |
there rs ⁱ++ xs = there (rs ⁱ++ xs) |
| 46 |
|
| 47 |
map : R ⇒ S → Infix R ⇒ Infix S |
| 48 |
map R⇒S (here pref) = here (Prefix.map R⇒S pref) |
| 49 |
map R⇒S (there inf) = there (map R⇒S inf) |
| 50 |
|
| 51 |
toView : ∀ {as bs} → Infix R as bs → View R as bs |
| 52 |
toView (here p) with inf Prefix.++ suff ← Prefix.toView p = MkView [] inf suff |
| 53 |
toView (there p) with MkView pref inf suff ← toView p = MkView (_ ∷ pref) inf suff |
| 54 |
|
| 55 |
fromView : ∀ {as bs} → View R as bs → Infix R as bs |
| 56 |
fromView (MkView [] inf suff) = here (Prefix.fromView (inf Prefix.++ suff)) |
| 57 |
fromView (MkView (a ∷ pref) inf suff) = there (fromView (MkView pref inf suff)) |