symmetries/Experiments/FreeStr.agda

142 lines
4.4 KiB
Plaintext
Raw Normal View History

2024-03-11 18:20:28 +00:00
{-# OPTIONS --cubical #-}
module Experiments.FreeStr where
open import Cubical.Foundations.Everything
open import Cubical.Foundations.Equiv
open import Cubical.Functions.Image
open import Cubical.HITs.PropositionalTruncation as P
open import Cubical.Data.Nat
open import Cubical.Data.FinData as F
open import Cubical.Data.List as L
open import Cubical.Data.List.FinData as F
open import Cubical.Data.Sigma
open import Cubical.Reflection.RecordEquiv
open import Cubical.HITs.SetQuotients as Q
open import Agda.Primitive
module _ {f a e n : Level} (σ : Sig f a) (τ : EqSig e n) (ε : seq σ τ) where
srel : (X : Type n) -> Tree σ X -> Tree σ X -> Type {!!}
srel X l r = sat σ τ ε {!!}
Fr : (X : Type n) -> walg σ
Fr X = (Tree σ X / {!!}) , {!!}
module _ {f a e n : Level} (σ : Sig f a) (τ : EqSig e n) where
evalEq : {X : Type n} -> (n : τ .name) -> (ρ : X -> τ .free n) -> Tree σ X -> Tree σ (τ .free n)
evalEq {X = X} n ρ = _♯ σ {X = X} {Y = TreeStr σ (τ .free n)} (leaf ∘ ρ)
eqs : {X : Type n} -> Tree σ X -> Tree σ X -> Type (-max (-max f a) (-max e n))
eqs {X = X} lhs rhs = (n : τ .name) (ρ : X -> τ .free n) -> evalEq n ρ lhs ≡ evalEq n ρ rhs
Free : Type n -> Type (-max (-max f a) (-max e n))
Free X = Tree σ X / eqs
module _ {f a e n : Level} (σ : Sig f a) (τ : EqSig e n) where
t2f : {X : Type n} -> Tree σ X -> Free σ τ X
t2f = Q.[_]
f2t : {X : Type n} -> Free σ τ X -> ∥ Tree σ X ∥₁
f2t F = let p = ([]surjective F) in P.map fst p
FreeStr : (X : Type n) -> Str (-max (-max (-max f a) e) n) σ
car (FreeStr X) = Free σ τ X
ops (FreeStr X) f o = {!!}
isSetStr (FreeStr X) = {!!}
-MonStrEq : Eqs -zero MonSig -MonStr
Eqs.name -MonStrEq = MonEq
Eqs.free -MonStrEq = MonEqFree
Eqs.lhs -MonStrEq = MonEqLhs
Eqs.rhs -MonStrEq = MonEqRhs
Eqs.equ -MonStrEq unitl = refl
Eqs.equ -MonStrEq unitr = funExt \v -> +-zero (v zero)
Eqs.equ -MonStrEq assocr = funExt \v -> sym (+-assoc (v zero) (v one) (v two))
Free-MonStr : (X : Type) -> Str -zero MonSig
Str.car (Free-MonStr X) = Free MonSig X
Str.ops (Free-MonStr X) e f = op e f
Str.ops (Free-MonStr X) ⊕ f = op ⊕ f
Str.isSetStr (Free-MonStr X) = isSetStr
Sig : (f a : Level) -> Type (-max (-suc f) (-suc a))
Sig f a = Σ[ F ∈ Type f ] (F -> Type a)
Op : {a x : Level} -> Type a -> Type x -> Type (-max a x)
Op A X = (A -> X) -> X
Str : {f a : Level} (x : Level) -> Sig f a -> Type (-max (-max f a) (-suc x))
Str {f} {a} x (F , ar) = Σ[ X ∈ Type x ] ((f : F) -> Op (ar f) X)
MonSig : Sig -zero -zero
MonSig = MonDesc , MonAr
MonStr = Str -zero MonSig
-MonStr : MonStr
-MonStr = , \{ e f -> 0
; ⊕ f -> f zero + f (suc zero) }
--
module FreeStr {f a : Level} (σ @ (F , ar) : Sig f a) where
data Free {x} (X : Type x) : Type {!!} where
η : X -> Free X
op : (f : F) -> Op (ar f) (Free X) -> Free X
isSetStr : isSet (Free X)
Op : (a : Level) -> -> Type a -> Type a
Op a n A = (Fin n -> A) -> A
Str : {f : Level} (a : Level) -> Sig f -> Type {!!}
Str {f} a (F , ar) = Σ[ A ∈ Type a ] ((f : F) -> Op a (ar f) A)
MonSig : Sig -zero
MonSig = Fin 2 , lookup (0 ∷ 2 ∷ [])
-MonStr : Str -zero MonSig
-MonStr = , F.elim {!!} (\_ -> 0) {!!}
F.elim (\{k} f -> Op -zero {!!} ) {!!} {!!}
(f : Fin 2) → (Fin (lookup (0 ∷ 2 ∷ []) f) → ) →
(f : fst MonSig) → Op -zero (snd MonSig f)
F.elim (\f -> Op -zero (rec 0 2 f) ) (\_ -> 0) (\_ -> {!!})
record FreeS ( : Level) (S : Type → Type ') : Type (-max (-suc ) ') where
field
F : Type -> Type
F-S : (A : Type ) -> S (F A)
η : (A : Type ) -> A -> F A
freeS : (S : Type -> Type ') -> FreeS S
monad T, T-alg
monads on hSet
record Monad { : Level} : Type (-suc ) where
field
T : Type -> Type
map : ∀ {A B} -> (A -> B) -> T A -> T B
η : ∀ {A} -> A -> T A
μ : ∀ {A} -> T (T A) -> T A
record T-Alg {} (T : Monad {}) : Type (-suc ) where
module T = Monad T
field
el : Type
alg : T.T el -> el
unit : alg ∘ T.η ≡ idfun _
action : alg ∘ T.map alg ≡ alg ∘ T.μ
record T-AlgHom {} {T : Monad {}} (α β : T-Alg T) : Type (-suc ) where
module T = Monad T
module α = T-Alg α
module β = T-Alg β
field
f : α.el -> β.el
f-coh : β.alg ∘ T.map f ≡ f ∘ α.alg