{-# OPTIONS --cubical --safe #-} open import Cubical.Core.Primitives open import Cubical.Data.List open import Cubical.Data.Unit open import Cubical.HITs.SetQuotients record Signature : Type₁ where field Sort : Type₀ Symbol : (domain : List Sort) → (codomain : Sort) → Type₀ data Vector {A : Type₀} (B : A → Type₀) : List A → Type₀ where [] : Vector B [] _∷_ : {x : A} {xs : List A} → B x → Vector B xs → Vector B (x ∷ xs) data Vector₂ {A : Type₀} {B : A → Type₀} (C : {x : A} → B x → B x → Type₀) : {xs : List A} → Vector B xs → Vector B xs → Type₀ where [] : Vector₂ C [] [] _∷_ : {x : A} {xs : List A} {v v' : B x} {vs vs' : Vector B xs} → C v v' → Vector₂ C vs vs' → Vector₂ C (v ∷ vs) (v' ∷ vs') module _ (Σ : Signature) where open Signature Σ record Structure : Type₁ where field Carrier : Sort → Type₀ Fun : {dom : List Sort} {cod : Sort} (f : Symbol dom cod) → Vector Carrier dom → Carrier cod -- Purely for convenience, we introduce shorthand notation: -- If f is a binary function symbol, then `op f x y` is short for `Fun f (x ∷ y ∷ [])`. OpType : List Sort → Sort → Type₀ OpType [] s = Carrier s OpType (x ∷ xs) s = Carrier x → OpType xs s op : {dom : List Sort} {cod : Sort} (f : Symbol dom cod) → OpType dom cod op {xs} {cod} f = go xs (Fun f) where go : (xs : List Sort) → (Vector Carrier xs → Carrier cod) → OpType xs cod go [] eval = eval [] go (x ∷ xs) eval = λ a → go xs (λ args → eval (a ∷ args)) module _ (Σ : Signature) where open Signature Σ data Term : Sort → Type₀ where _·_ : {dom : List Sort} {cod : Sort} → (f : Symbol dom cod) → Vector Term dom → Term cod freeStructure : Structure Σ freeStructure = record { Carrier = Term; Fun = _·_ } module _ (Σ : Signature) (A : Structure Σ) where open Signature Σ open Structure A module _ (_≈_ : {s : Sort} → Carrier s → Carrier s → Type₀) where -- _≈'_ is the congruence relation generated by _≈_ data _≈'_ : {s : Sort} → Carrier s → Carrier s → Type₀ where lift : {s : Sort} {x y : Carrier s} → x ≈ y → x ≈' y cong : {dom : List Sort} {cod : Sort} {f : Symbol dom cod} → {xs ys : Vector Carrier dom} → Vector₂ _≈'_ xs ys → Fun f xs ≈' Fun f ys quotientStructure : Structure Σ quotientStructure = record { Carrier = λ s → Carrier s / _≈'_ ; Fun = {!!} } data MonoidSymbol : List Unit → Unit → Type₀ where ε₀ : MonoidSymbol [] tt ⋄₀ : MonoidSymbol (tt ∷ tt ∷ []) tt monoidSignature : Signature monoidSignature = record { Sort = Unit; Symbol = MonoidSymbol } module _ (A : Structure monoidSignature) where open Structure A ε = op ε₀ _⋄_ = op ⋄₀ data MonoidLaw : Carrier tt → Carrier tt → Type₀ where unitₗ : (x : Carrier tt) → MonoidLaw (ε ⋄ x) x unitᵣ : (x : Carrier tt) → MonoidLaw (x ⋄ ε) x assoc : (x y z : Carrier tt) → MonoidLaw ((x ⋄ y) ⋄ z) (x ⋄ (y ⋄ z)) freeMonoid : Structure monoidSignature freeMonoid = quotientStructure monoidSignature (freeStructure monoidSignature) (MonoidLaw (freeStructure monoidSignature))