X and Y <=> forall Y, (A -> B -> Y) -> Y
We can name X and Y as R, R satisfies:
A -> B -> R
That means R can be created from both A and B.
forall Y, (A -> B -> Y) -> R -> Y
That means any other Y that can be created from both A and B can be created from R, too.
So, no matter how and what Y we want to create from A and B, we can store A and B into R temporality, then create Y from R. Such storing is called as currying.
we can also name R as product type.
X or Y <=> forall Y, (A -> Y) -> (B -> Y) -> Y
We can name X or Y as R, R satisfies:
A -> R
B -> R
That means R can be created from A or created from B.
forall Y, (A -> Y) -> (B -> Y) -> R -> Y
That means any other Y that can be created from A or created from B can be created from R, too.
So, no matter how and what Y we want to create from A or B, we can store A or B into R temporality, then create Y from R. Such storing is kind of type erasure.
we can also name R as sum type.
exist X, P(X) <=> forall Y, (forall X, P(X) -> Y) -> Y
We can name exist X, P(X) as R, R satisfies:
forall X, P(X) -> R
That means R can be created from any P(X).
forall Y, (forall X, P(X) -> Y) -> R -> Y
That means any other Y that can be created from any P(X) can be created from R, too.
So, no matter how and what Y we want to create from any P(X), we can store P(X) into R temporality, then create Y from R. Such storing is kind of type erasure, too.
we can also name R as existential type.
here is the existential type definition in Coq with an example:
Inductive my_ex_t (P: Type -> Type) := my_ex: forall (A: Type), (P A) -> my_ex_t P. Definition my_ex_eq1 {Y: Type} {P: Type -> Type}: (forall A: Type, (P A) -> Y) -> (my_ex_t P -> Y). intros temp_fun value. destruct value. exact (temp_fun A p). Defined. Definition my_ex_eq2 {Y: Type} {P: Type -> Type}: (my_ex_t P -> Y) -> (forall A: Type, (P A) -> Y). intros ex_fun A pa. apply ex_fun. apply (my_ex P A). apply pa. Defined. Definition add_1_fun_t (A: Type) := A -> A. Definition not_t (A: Type) := A -> bool. Definition not_0_nat: not_t nat. intros n. case n. - exact false. - intros _. exact true. Defined. Definition not_1_nat: not_t nat. intros n. case n. - exact true. - intros n'. case n'. + exact false. + intros _. exact true. Defined. Print S. Definition func_table_t(A: Type) := (prod (prod A (add_1_fun_t A)) (not_t A)). Definition add_check (A: Type) (func_table: func_table_t A): bool. destruct func_table. destruct p. apply n. apply a0. apply a. Defined. Definition func_table0 := pair (pair 0 S) not_0_nat. Definition func_table1 := pair (pair 0 S) not_1_nat. Compute (my_ex_eq1 add_check (my_ex func_table_t nat func_table0)). Compute (my_ex_eq1 add_check (my_ex func_table_t nat func_table1)).