std:Equal
lib/Equal.omg
lib/Equal.omg37 lines
1{- Propositional equality.
2
3 `x === y` is the type of proofs that `x` and `y` are equal (the builtin
4 `Equal`). Its only constructor is `refl : x === x`, and `assert : T`
5 builds a proof of an equation `T` whose sides have the same normal form.
6 The eliminator is the builtin `Equal/elim` (the J rule).
7-}
8
9let sym
10 : forall {l : Level} {a : Type l} {x : a} {y : a} -> x === y -> y === x
11 = \{l} {a} {x} {y} p -> Equal/elim (\(z : a) (_ : x === z) -> z === x) refl p
12
13let trans
14 : forall {l : Level} {a : Type l} {x : a} {y : a} {z : a} -> x === y -> y === z -> x === z
15 = \{l} {a} {x} {y} {z} p q -> Equal/elim (\(w : a) (_ : y === w) -> x === w) p q
16
17-- Functions respect equality.
18let cong
19 : forall {la lb : Level} {a : Type la} {b : Type lb} {x : a} {y : a} (f : a -> b)
20 -> x === y
21 -> f x === f y
22 = \{la} {lb} {a} {b} {x} {y} f p -> Equal/elim (\(z : a) (_ : x === z) -> f x === f z) refl p
23
24-- Transport: a property that holds of `x` holds of anything equal to `x`.
25let subst
26 : forall {la lb : Level} {a : Type la} {x : a} {y : a} (P : a -> Type lb)
27 -> x === y
28 -> P x
29 -> P y
30 = \{la} {lb} {a} {x} {y} P p px -> Equal/elim (\(z : a) (_ : x === z) -> P z) px p
31
32-- Equal types have the same inhabitants.
33let cast
34 : forall {l : Level} {a : Type l} {b : Type l} -> a === b -> a -> b
35 = \{l} {a} {b} p x -> subst (\(t : Type l) -> t) p x
36
37in { sym, trans, cong, subst, cast }