module A201802.WIP.CoquandList where
open import A201801.Prelude
open import A201801.Category
open import A201802.WIP.Bool
open import A201802.WIP.Name
infix 6 _,_β¦_
mutual
data List (π : Set) : Set
where
β : List π
_,_β¦_ : (Ξ : List π) (x : Name) β π β {{_ : T (fresh x Ξ)}}
β List π
fresh : β {π} β Name β List π β Bool
fresh x β = true
fresh x (Ξ , y β¦ A) = and (x β y) (fresh x Ξ)
infix 4 _β_β¦_
data _β_β¦_ {π} : List π β Name β π β Set
where
zero : β {Ξ A x} β {{_ : T (fresh x Ξ)}}
β Ξ , x β¦ A β x β¦ A
suc : β {Ξ A B x y} β {{_ : T (fresh y Ξ)}}
β Ξ β x β¦ A
β Ξ , y β¦ B β x β¦ A
notβ : β {π A x} β {Ξ : List π} {{_ : T (fresh x Ξ)}}
β Β¬ (Ξ β x β¦ A)
notβ {x = x} {{Ο}} zero with x β x
notβ {x = x} {{()}} zero | yes refl
notβ {x = x} {{Ο}} zero | no xβ’x = refl β― xβ’x
notβ {x = x} {{Ο}} (suc {y = y} i) with x β y
notβ {x = x} {{()}} (suc {y = .x} i) | yes refl
notβ {x = x} {{Ο}} (suc {y = y} i) | no xβ’y = i β― notβ
uniqβ : β {π A x} β {Ξ : List π} (i j : Ξ β x β¦ A)
β i β‘ j
uniqβ zero zero = refl
uniqβ zero (suc j) = j β― notβ
uniqβ (suc i) zero = i β― notβ
uniqβ (suc i) (suc j) = suc & uniqβ i j
infix 4 _β_
data _β_ {π} : List π β List π β Set
where
done : β {Ξ} β Ξ β β
step : β {Ξ Ξβ² A x} β {{_ : T (fresh x Ξ)}}
β Ξβ² β Ξ β Ξβ² β x β¦ A
β Ξβ² β Ξ , x β¦ A
putβ : β {π} β {Ξ Ξβ² : List π}
β (β {A x} β Ξ β x β¦ A β Ξβ² β x β¦ A)
β Ξβ² β Ξ
putβ {Ξ = β} f = done
putβ {Ξ = Ξ , x β¦ A} f = step (putβ (f β suc)) (f zero)
getβ : β {π A x} β {Ξ Ξβ² : List π}
β Ξβ² β Ξ β Ξ β x β¦ A
β Ξβ² β x β¦ A
getβ (step Ξ· i) zero = i
getβ (step Ξ· i) (suc j) = getβ Ξ· j
uniqβ : β {π} β {Ξ Ξβ² : List π}
β (Ξ·β Ξ·β : Ξβ² β Ξ)
β Ξ·β β‘ Ξ·β
uniqβ done done = refl
uniqβ (step c i) (step cβ² j) = step & uniqβ c cβ² β uniqβ i j
dropβ : β {π A x} β {Ξ Ξβ² : List π} {{_ : T (fresh x Ξβ²)}}
β Ξβ² β Ξ
β Ξβ² , x β¦ A β Ξ
dropβ done = done
dropβ (step Ξ· i) = step (dropβ Ξ·) (suc i)
keepβ : β {π A x} β {Ξ Ξβ² : List π} {{_ : T (fresh x Ξβ²)}} {{_ : T (fresh x Ξ)}}
β Ξβ² β Ξ
β Ξβ² , x β¦ A β Ξ , x β¦ A
keepβ Ξ· = step (dropβ Ξ·) zero
idβ : β {π} β {Ξ : List π}
β Ξ β Ξ
idβ = putβ id
_ββ_ : β {π} β {Ξ Ξβ² Ξβ³ : List π}
β Ξβ² β Ξ β Ξβ³ β Ξβ²
β Ξβ³ β Ξ
Ξ·β ββ Ξ·β = putβ (getβ Ξ·β β getβ Ξ·β)
lidββ : β {X} β {Ξ Ξβ² : List X}
β (Ξ· : Ξβ² β Ξ)
β idβ ββ Ξ· β‘ Ξ·
lidββ Ξ· = uniqβ (idβ ββ Ξ·) Ξ·
ridββ : β {X} β {Ξ Ξβ² : List X}
β (Ξ· : Ξβ² β Ξ)
β Ξ· ββ idβ β‘ Ξ·
ridββ Ξ· = uniqβ (Ξ· ββ idβ) Ξ·
assocββ : β {X} β {Ξ Ξβ² Ξβ³ Ξβ΄ : List X}
β (Ξ·β : Ξβ² β Ξ) (Ξ·β : Ξβ³ β Ξβ²) (Ξ·β : Ξβ΄ β Ξβ³)
β (Ξ·β ββ Ξ·β) ββ Ξ·β β‘ Ξ·β ββ (Ξ·β ββ Ξ·β)
assocββ Ξ·β Ξ·β Ξ·β = uniqβ ((Ξ·β ββ Ξ·β) ββ Ξ·β) (Ξ·β ββ (Ξ·β ββ Ξ·β))
instance
πππ§ : β {π} β Category (List π) _β_
πππ§ = record
{ id = idβ
; _β_ = _ββ_
; lidβ = lidββ
; ridβ = ridββ
; assocβ = assocββ
}
data All {π} (π : π β Set) : List π β Set
where
β : All π β
_,_ : β {Ξ A x} β All π Ξ β π A β {{_ : T (fresh x Ξ)}}
β All π (Ξ , x β¦ A)
get : β {π π A x} β {Ξ : List π}
β All π Ξ β Ξ β x β¦ A
β π A
get (ΞΎ , a) zero = a
get (ΞΎ , b) (suc i) = get ΞΎ i
maps : β {π π π} β {Ξ : List π}
β (β {A} β π A β π A) β All π Ξ
β All π Ξ
maps π£ β = β
maps π£ (ΞΎ , a) = maps π£ ΞΎ , π£ a