Skip to content

Instantly share code, notes, and snippets.

View bond15's full-sized avatar

bond15

View GitHub Profile
@bond15
bond15 / copattern.agda
Last active July 7, 2021 15:40
Copattern matching
{-# OPTIONS --copatterns #-}
module copattern where
record Bar : Set where
field
x : List Unit
y : Unit
z : ℕ
open Bar
{-# OPTIONS --copatterns #-}
module streams where
record Stream (A : Set) : Set where
coinductive
field
hd : A
tl : Stream A
open Stream
@bond15
bond15 / nat.thy
Created July 16, 2021 18:01
Coq Nat Mon
Inductive Nat : Type :=
| z : Nat
| suc : Nat -> Nat.
Print Nat_ind.
Fixpoint plus (n m : Nat): Nat :=
match n with
| z => m
@bond15
bond15 / cube.agda
Created July 17, 2021 00:11
Cubical Agda Int
{-# OPTIONS --cubical #-}
module cube where
open import Data.Nat
open import Cubical.Foundations.Prelude
data Int : Set where
pos : (n : ℕ) -> Int
neg : (n : ℕ) -> Int
@bond15
bond15 / AOC.agda
Last active July 18, 2021 02:11
Axiom Of Choice in DTT
module AOC where
open import Agda.Builtin.Sigma
open import Relation.Binary.PropositionalEquality using (_≡_;refl)
infix 0 _≈_
record _≈_ (A B : Set) : Set where
field
to : A → B
from : B → A
@bond15
bond15 / Mon.agda
Last active July 22, 2021 15:58
Option Monad Agda
{-# OPTIONS --type-in-type #-}
-- ^^ ignoring sizing
module Mon where
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
REL : Set -> Set -> Set
REL A B = A -> B -> Set
Rel : Set -> Set
Rel A = REL A A
@bond15
bond15 / Mon.hs
Created July 22, 2021 16:00
Option ex
module Mon where
data Option a = None | Some a deriving Show
--class Functor f where
-- fmap :: (a -> b) -> f a -> f b
instance Functor Option where
fmap f None = None
@bond15
bond15 / NatTrans.agda
Created August 22, 2021 01:24
Natural Transformation: Option -> List
{-# OPTIONS --type-in-type #-}
module Category where
open import Base
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; trans; sym; cong; cong₂ ; cong-app; subst)
REL : Set -> Set -> Set
REL A B = A -> B -> Set
Rel : Set -> Set
@bond15
bond15 / TM.agda
Last active January 13, 2022 00:27
Turing Machines as Natural Transformations between Polynomial Functors
module TM where
open import Data.Integer
data V : Set where
One Zero Empty : V
data HeadDir : Set where
L R : HeadDir
-- An encoding of Polynomial Functors
module PhoasEx where
data One : Set where
one : One
data type : Set where
Nat Unit : type
_⇒_ : type -> type -> type
Value : type -> Set
Value Nat = ℕ