Skip to content

Instantly share code, notes, and snippets.

@palladin
Created September 10, 2016 16:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save palladin/eec79457ae516062f8ce71c7c9e6fdda to your computer and use it in GitHub Desktop.
Save palladin/eec79457ae516062f8ce71c7c9e6fdda to your computer and use it in GitHub Desktop.
Generic programming in Cubical type theory
module test where
import prelude
import univalence
data list (A : U) = nil | cons (x : A) (xs : list A)
data bool = false | true
data nat = zero | suc (n : nat)
one : nat = suc zero
two : nat = suc one
three : nat = suc two
Pair (A : U) (B : U) : U = (_ : A) * B
swapf (t : Pair nat nat) : Pair nat nat = (t.2, t.1)
swap (t : Pair nat nat) : Path (Pair nat nat) (swapf (swapf t)) t =
refl (Pair nat nat) t
There (A : U) : U = list ((_ : bool) * A)
path : Path U (Pair nat nat) (Pair nat nat) =
isoPath (Pair nat nat) (Pair nat nat) swapf swapf swap swap
DB : U = list ((_ : bool) * Pair nat nat)
convert (db : DB) : DB = subst U There (Pair nat nat) (Pair nat nat) path db
example : DB =
cons (true, (one, two))
(cons (false, (two, three))
(cons (true, (three, one)) nil))
example' : DB = convert example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment