Skip to content

Instantly share code, notes, and snippets.

@clayrat
clayrat / KVList.agda
Last active September 26, 2024 23:54
KV lists
open import Prelude
open import Data.Empty
open import Data.Bool renaming (elim to elimᵇ ; rec to recᵇ)
open import Data.Maybe
open import Data.List
open import Data.List.Operations.Discrete
open import Data.List.Correspondences.Unary.All
open import Data.List.Correspondences.Unary.Has
open import Data.List.Correspondences.Unary.Related
open import Data.List.Correspondences.Binary.Perm
@clayrat
clayrat / Div3DFA.agda
Last active September 6, 2024 09:50
Div3DFA
module Div3DFA where
open import Prelude
open import Data.Bool
open import Data.Nat
open import Data.Nat.Order.Base
open import Data.Nat.DivMod
open import Data.Nat.DivMod.Base
open import Data.List
open import Data.Reflects
@clayrat
clayrat / Powerset.agda
Created July 29, 2024 21:09
Powerset sup-lattice
{-# OPTIONS --safe #-}
module Order.SupLattice.Powerset where
open import Categories.Prelude
open import Meta.Prelude
open import Foundations.Equiv.Size
open import Data.Empty
open import Data.Unit
open import Data.Sum
@clayrat
clayrat / DepPrism.agda
Last active June 18, 2024 20:51
Jules' dependent prism
module DepPrism where
open import Prelude
open import Data.Empty
open import Data.Sum
private variable
ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level
X : 𝒰 ℓ₁
@clayrat
clayrat / Bag.agda
Last active June 11, 2024 12:09
Bij
{-# OPTIONS --safe --backtracking-instance-search #-}
module Bag where
open import Prelude
open import Data.Nat.Base
open import Data.Fin.Computational.Base
open import Data.Fin.Computational.Instances.Finite
open import Structures.FinSet
open import Bij
@clayrat
clayrat / AccFinite.v
Last active May 24, 2024 13:46
Acc is finite
CoInductive stream (A : Type) : Type :=
| Cons : A
-> stream A
-> stream A.
CoInductive infiniteDecreasingChain A (R : A -> A -> Prop) : stream A -> Prop :=
| ChainCons : forall x y s, infiniteDecreasingChain A R (Cons A y s)
-> R y x
-> infiniteDecreasingChain A R (Cons A x (Cons A y s)).
@clayrat
clayrat / Bush.hs
Created February 14, 2024 15:33
a binary tree automaton
data Bush n l b = Bsh (l -> b) (n -> Bush n l (Bush n l b))
-- polymorphic recursion
mapb :: (b -> c) -> Bush n l b -> Bush n l c
mapb f (Bsh g k) = Bsh (f . g) (\a -> mapb (mapb f) (k a))
data BT n l = L l | Sp (BT n l) n (BT n l)
lamBT :: (BT n l -> b) -> Bush n l b
lamBT f = Bsh (f . L) (\a -> lamBT (\t -> lamBT (\u -> f (Sp t a u))))
@clayrat
clayrat / sub-even.agda
Created August 24, 2023 17:47
Evenness examples from "Subtyping Without Reduction"
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Even where
open import Prelude
open import Data.Unit
open import Data.Empty
open import Data.Bool
open import Data.Nat
open import Data.Nat.Order.Inductive
@clayrat
clayrat / qh.agda
Last active June 13, 2024 13:16
Examples from QuotientHaskell paper in Cubical Agda (+ cubical-mini)
{-# OPTIONS --safe #-}
module qh where
-- https://www.cs.nott.ac.uk/~pszgmh/quotient-haskell.pdf
open import Prelude
open import Meta.Prelude
open import Data.Bool
open import Data.Empty
From mathcomp Require Import ssreflect ssrbool ssrfun ssrnat eqtype.
From pcm Require Import options axioms prelude pred.
From pcm Require Import pcm unionmap heap.
From htt Require Import options interlude model heapauto.
(* counter that hides local state with an abstract predicate *)
Record cnt : Type :=
Counter {inv : nat -> Pred heap;
method : {v : nat}, STsep (inv v,