Phi*_*ell 13 parametric-polymorphism idris free-theorem
对于足够多态的类型,参数可以唯一地确定函数本身(有关详细信息,请参阅Wadler的定理免费!).例如,唯一具有类型的总函数forall t. t -> t是标识函数id.
是否有可能在伊德里斯陈述并证明这一点?(如果在伊德里斯内部无法证明,无论如何都是真的吗?)
以下是我的尝试(我知道函数相等不是Idris中的原始概念,所以我断言泛型类型的任何函数t -> t总是返回与身份函数返回的结果相同的结果):
%default total
GenericEndomorphism: Type
GenericEndomorphism = (t: Type) -> (t -> t)
id_is_an_example : GenericEndomorphism
id_is_an_example t = id
id_is_the_only_example : (f : GenericEndomorphism) -> (t : Type) -> (x : t) -> f t x = x
id_is_the_only_example f t x = ?id_is_the_only_example_rhs
Run Code Online (Sandbox Code Playgroud)
由此产生的洞是:
- + Main.id_is_the_only_example_rhs [P]
`-- f : GenericEndomorphism
t : Type
x : t
-------------------------------------------------------
Main.id_is_the_only_example_rhs : f t x = x
Run Code Online (Sandbox Code Playgroud)