Skip to content

Instantly share code, notes, and snippets.

View kontheocharis's full-sized avatar
〰️

Constantine Theocharis kontheocharis

〰️
  • University of St Andrews
  • UK
  • 12:09 (UTC)
View GitHub Profile
@kontheocharis
kontheocharis / PropEquality.agda
Created November 18, 2026 19:20
Prop-valued equality with coercion in Agda
{-# OPTIONS --prop --rewriting #-}
variable
A A' : Set _
B B' : A → Set _
x y z : A
infix 4 _≡_
data _≡_ {ℓ} {A : Set ℓ} (x : A) : A → Prop ℓ where
refl : x ≡ x
@kontheocharis
kontheocharis / Reconstruct.agda
Created October 29, 2026 15:03
Reconstructing types from erased bidirectional syntax
{-# OPTIONS --erasure #-}
module Reconstruct where
open import Data.Unit
open import Data.Product
data Ty : Set where
Π : Ty → Ty → Ty
@kontheocharis
kontheocharis / Omega.agda
Created October 6, 2026 14:50
Infinite list of dependently-typed sets is a presheaf on ω.
open import Data.Nat
open import Data.Product
open import Relation.Binary.PropositionalEquality
-- Limits of ω-chains E 0 <- E 1 <- ...
record Limit {ℓ} (E : ℕ → Set ℓ) (prev : ∀ n → E (suc n) → E n) : Set ℓ where
field
seq : ∀ n → E n
coh : ∀ n → prev n (seq (suc n)) ≡ seq n
@kontheocharis
kontheocharis / Unsized-2.agda
Created September 2, 2026 17:19
Unboxed arrays in a representation-indexed type theory
{-# OPTIONS --prop --rewriting --erasure #-}
module Unsized-2 where
open import Agda.Builtin.Nat using (Nat; suc; zero)
open import Data.Fin.Base using (Fin; suc; zero)
open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl)
-- Bytes
postulate
@kontheocharis
kontheocharis / StagePoly.agda
Created May 18, 2026 23:38
Stage polymorphism with HOAS in Agda
open import Agda.Builtin.Equality
{-# BUILTIN REWRITE _≡_ #-}
data Stage : Set where `0 `1 : Stage
postulate
Ty : Stage → Set
Tm : ∀ {s} → Ty s → Set
@kontheocharis
kontheocharis / Para.idr
Created November 2, 2025 14:36
Algebras and paramorphisms for a simple class of signatures in Idris2
import Data.Fin
import Data.Vect
import Data.Vect.Quantifiers
-- No telescopes, no indexing (parameters still possible), no displayed
-- algebras, just paramorphisms.
-- This is the type of descriptions/signatures for constructor data.
-- Each operation (constructor) is a sequence of arguments, either data or
-- recursive calls.
@kontheocharis
kontheocharis / Russell.idr
Last active October 29, 2025 16:32
Russell's paradox in Idris2
%default total
-- A set is an index type, and a set for each index, inductively.
record Set where
constructor MkSet
i : Type
f : i -> Set
-- Set `a` is contained in set `b` if there is an index in `b` at which we find
-- a set equal to `a`
@kontheocharis
kontheocharis / PropTrunc.idr
Created July 24, 2025 12:47
Propositional truncation in Idris2
import Data.DPair
import Decidable.Equality
interface IsProp a where
prop : (0 x : a) -> (0 y : a) -> x = y
0 IsPropD : {a : Type} -> (p : a -> Type) -> Type
IsPropD {a} p = (0 m : a) -> IsProp (p m)
-- POSTULATES
@kontheocharis
kontheocharis / QTTinTT.agda
Last active July 13, 2025 11:10
Dependent type theory with irrelevant binders, in the style of QTT
-- Definition of a CWF with irrelevant binders in Agda, in the style of QTT.
----------------------------------------------------------------------------
-- The CWF formulation of quantitative type theory (Atkey 2018) is basically a
-- base CWF B, a resourced CWF-like thing E, and a functor U : E → B that
-- preserves everything.
--
-- It is really annoying to define this directly as two syntaxes and a functor
-- between them. Instead, we can define a base CWF B, and a displayed CWF E over B.
-- We can recover the usual functorial formulation by taking the total space of E.
@kontheocharis
kontheocharis / FakeSOGAT.agda
Last active June 11, 2025 19:26
Dependent type theory in Agda without explicit contexts
module FakeSOGAT where
open import Relation.Binary.PropositionalEquality
infixr 3 _⇒_
_⇒_ : ∀ {I : Set} → (A : I → Set) → (I → Set) → (I → Set)
(A ⇒ B) j = A j → B j
∀[_] : ∀ {I : Set} → (I → Set) → Set
∀[_] {I} P = {Γ : I} → P Γ