`Refl` thing in Calculus of Constructions?

id : \/a : *. a -> a
id = \a : *. \x : a. x

eqn : \/a : *. a -> a -> *
eqn = \a : *. \x : a. \y : a. \/p : (a -> *). p x -> p y

refl : \/a : *. \/x : a. eqn a x x
refl = \a : *. \x : a. \p : (a -> *). id (p x)

where \/ is the pi-constructor and \is the lambda-constructor.

I think that the idea of Church-Scott Encoding is to define a type as its elimination rule and its constructors as its introduction rules.

either is a good example:

either : * -> * -> *
either = \a : *. \b : *. \/r : *. (a -> r) -> (b -> r) -> r 

left : \/a : *. \/b : *. a -> either a b
left = \a : *. \b : *. \x : a. \r : *. \left1 : (a -> r). \right1 : (b -> r). left1 x

right : \/a : *. \/b : *. b -> either a b
right = \a : *. \b : *. \y : b. \r : *. \left1 : (a -> r). \right1 : (b -> r). right1 y

either is defined as the elimination rule of disjunction.

By this idea, eqn a x y must be defined as the liebniz rule \/p : (a -> *). p x -> p y, because the elimination rule of equation is the liebniz rule.


+) a proof of 1 != 0:

bottom : *
bottom = \/r : *. r

nat : *
nat = \/r : *. r -> (r -> r) -> r

zero : nat
zero = \r : *. \z : r. \s : (r -> r). z

succ : nat -> nat
succ = \n : nat. \r : *. \z : r. \s : (r -> r). s (n r z s)

id : \/a : *. a -> a
id = \a : *. \x : a. x

eqn : \/a : *. a -> a -> *
eqn = \a : *. \x : a. \y : a. \/p : (a -> *). p x -> p y

refl : \/a : *. \/x : a. eqn a x x
refl = \a : *. \x : a. \p : (a -> *). id (p x)

goal : eqn nat (succ zero) zero -> bottom
goal = \one_is_zero : (\/p : (nat -> *). p (succ zero) -> p zero). \r : *. one_is_zero (\n : nat. n * r (\a : *. r -> a)) (id r)

The standard Church-encoding of a :~: b in CoC is:

(a :~: b) =
   forall (P :: * -> * -> *).
      (forall c :: *. P c c) ->
      P a b

Refl being

Refl a :: a :~: a
Refl a =
   \ (P :: * -> * -> *)
     (h :: forall (c::*). P c c) ->
     h a

The above formulates equality between types. For equality between terms, the :~: relation must take an additional argument t :: *, where a b :: t.

((:~:) t a b) = 
   forall (P :: t -> t -> *).
      (forall c :: t. P c c) ->
      P a b

Refl t a :: (:~:) t a a
Refl t a =
   \ (P :: t -> t -> *)
     (h :: forall (c :: t). P c c) ->
     h a