{-# OPTIONS --postfix-projections #-}
module irreflexive-lt where
open import Size
postulate
𝟘 : Size
data Size≲ : (j : Size) → Set where
≲∞ : (i : Size) → Size≲ ∞
<→≲ : ∀ {j} (i : Size< j) → Size≲ j
from≲ : ∀ {j} → Size≲ j → Size
from≲ (≲∞ i) = i
from≲ (<→≲ i) = i
∞′ : Size≲ ∞
∞′ = ≲∞ ∞
data ℕ (i : Size) : Set where
zero : ℕ i
suc : (j : Size< i) → ℕ j → ℕ i
suc₁ : ℕ ∞ → ℕ ∞
suc₁ zero = suc 𝟘 zero
suc₁ (suc j x) = suc (↑ j) (suc j x)
caseℕ : {T : Set} → (i : Size) → ℕ i → T → ((j : Size< i) → ℕ j → T) → T
caseℕ i zero z s = z
caseℕ i (suc j n) z s = s j n
indℕ : (P : (i : Size) → ℕ i → Set)
→ ((i : Size) → P i zero)
→ ((i : Size) (j : Size< i) (n : ℕ j) → P j n → P i (suc j n))
→ (i : Size) (n : ℕ i) → P i n
indℕ P Z S i zero = Z i
indℕ P Z S i (suc j n) = S i j n (indℕ P Z S j n)
record 𝕊 (A : Set) (i : Size) : Set where
coinductive
field
head : A
tail : (j : Size< i) → 𝕊 A j
open 𝕊
variable
A B : Set
tail₁ : 𝕊 A ∞ → 𝕊 A ∞
tail₁ xs .head = head {i = 𝟘} (tail xs 𝟘)
tail₁ xs .tail j = tail (tail xs (↑ j)) j
replicate : (i : Size) → A → 𝕊 A i
replicate i a .head = a
replicate i a .tail j = replicate j a
map𝕊 : (A → B) → (i : Size) → 𝕊 A i → 𝕊 B i
map𝕊 f i xs .head = f (head xs)
map𝕊 f i xs .tail j = map𝕊 f j (tail xs j)
data List (A : Set) : Set where
[] : List A
_∷_ : A → List A → List A
mapList : (A → B) → List A → List B
mapList f [] = []
mapList f (x ∷ xs) = f x ∷ mapList f xs
data Tree (A : Set) (i : Size) : Set where
leaf : A → Tree A i
node : (j : Size< i) → List (Tree A j) → Tree A i
mapTree : (A → B) → (i : Size) → Tree A i → Tree B i
mapTree f i (leaf x) = leaf (f x)
mapTree f i (node j cs) = node j (mapList (mapTree f j) cs)
mutual
data CoList (A : Set) (i : Size) : Set where
[] : CoList A i
_∷_ : A → CoList′ A i → CoList A i
record CoList′ (A : Set) (i : Size) : Set where
coinductive
field
force : (j : Size< i) → CoList A j
open CoList′
open import Data.Product using (∃-syntax)
open import Relation.Binary.PropositionalEquality using (_≡_ ; refl ; inspect ; [_])
open import Relation.Binary.HeterogeneousEquality using (_≅_ ; refl)
postulate
force-parametric : ∀ {A i} (xs : CoList′ A i) (j j′ : Size< i)
→ xs .force j ≅ xs .force j′
size-parametric : ∀ {T : Size< ∞ → Set} (f : (i : Size< ∞) → T i)
→ (j j′ : Size< ∞)
→ f j ≅ f j′
mutual
data _≈_ {A i j} : CoList A i → CoList A j → Set where
[] : [] ≈ []
_∷_ : ∀ {x y xs ys}
→ x ≡ y
→ xs ≈′ ys
→ (x ∷ xs) ≈ (y ∷ ys)
record _≈′_ {A i j} (xs : CoList′ A i) (ys : CoList′ A j) : Set where
coinductive
field
force : (k : Size< i) (l : Size< j) → xs .force k ≈ ys .force l
open _≈′_
force∞ : CoList′ A ∞ → CoList A ∞
force∞ {A} xs with xs .force 𝟘
... | [] = []
... | y ∷ ys = y ∷ ys′
where
ys′ : CoList′ A ∞
ys′ .force i with xs .force (↑ i)
... | [] = []
... | z ∷ zs = zs .force i
𝕊→CoList : (i : Size) → 𝕊 A i → CoList A i
𝕊→CoList i xs = head xs ∷ λ { .force j → 𝕊→CoList j (tail xs j) }