playground/agda/hott.agda

135 lines
3.0 KiB
Agda
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Type = Set
data Bool : Type where
true false : Bool
not : Bool Bool
not true = false
not false = true
idBool : Bool Bool
idBool x = x
idBool' : Bool Bool
idBool' = λ (x : Bool) x
id' : (X : Type) X X
id' X x = x
id : {X : Type} X X
id x = x
idBool'' : Bool Bool
idBool'' = id' _ -- asdf
example : {P Q : Type} P (Q P)
example {P} {Q} p = f
where
f : Q P
f _ = p
example2 : {P Q : Type} P (Q P)
example2 {P} {Q} p = (λ q p)
-- example : {P Q : Type} → P → (Q → P)
-- example {P} {Q} p = f
-- example : {P Q : Type} → P → (Q → P)
-- example {P} {Q} p = f
-- open import binary-products
--
-- ex : {P Q : Type} → P x Q → Q x
data : Type where
zero :
succ :
three :
three = succ (succ (succ zero))
{-# BUILTIN NATURAL #-}
-- a pragma
three' :
three' = 3 -- same as three
-- Dependent types again
D : Bool Type
D true =
D false = Bool
-- 'mix-fix' operator
if_then_else : {X : Type} Bool X X X
if true then x else y = x
if false then x else y = y
if[_]_then_else_ : (X : Bool Type)
(b : Bool)
X true
X false
X b
if[ X ] true then x else y = x
if[ X ] false then x else y = y
-- Π type
unfamiliar : (b : Bool) D b
unfamiliar b = if[ D ] b then 3 else false
-- A type indexed by a type
data List (A : Type) : Type where
[] : List A
_::_ : A List A List A
ff : Type Type
ff = List
-- okay, list is indeed Type → Type
sample-list₀ : List
sample-list₀ = 0 :: (1 :: (2 :: [])) -- brackets not really needed here, it's right associative
infix 10 _::_
-- brackets not really needed here, it's right associative
-- sample-list1 : List
-- sample-list1 = 0 :: 1 :: 2 :: []
length : {X : Type} List X
length [] = 0
length (x :: xs) = succ (length xs)
-- arbitrary recursive definitions not possible. Just like Coq.
-- Recursions got to be structurally smaller.
-- On a sub-term.
-elim : {A : Type}
A 0 -- base case
((k : ) A k A (succ k)) -- induction step
(n : ) A n
-elim {A} a f = h
where
h : (n : ) A n
h zero = a
h (succ n) = f n IH
where
IH : A n
IH = h n -- induction hypothesis
-elim' : {A : Type}
A 0 -- base case
((k : ) A k A (succ k)) -- induction step
(n : ) A n
-elim' {A} a f zero = a
-elim' {A} a f (succ n) = f n (-elim' a f n)
-- Elimination principal for lists
List-elim : {X : Type} (A : List X Type)
A [] -- base case
((x : X) (xs : List X) A xs A (x :: xs)) -- induction step
(xs : List X) A xs
List-elim {X} A a f = h
where
h : (xs : List X)