Idris 为我自己的平等使用重写?
我对平等的定义如下:Idris 为我自己的平等使用重写?,idris,Idris,我对平等的定义如下: data Equal : x -> y -> Type where Reflexive : Equal a a 每当我想使用重写语法时,我需要(a=b)类型的东西,因此我创建了: makeEquitable : Equal x y -> x = y makeEquitable Reflexive = Refl 现在我可以做makeequality(uu:equalabb),然后我可以用它来重写东西。我想简化这一点,我研究了replace,我并不
data Equal : x -> y -> Type where
Reflexive : Equal a a
每当我想使用重写
语法时,我需要(a=b)
类型的东西,因此我创建了:
makeEquitable : Equal x y -> x = y
makeEquitable Reflexive = Refl
现在我可以做
makeequality(uu:equalabb)
,然后我可以用它来重写东西。我想简化这一点,我研究了replace
,我并不真正理解replace:(x=y)->px->py
。这个P
东西是一个内置的Idris属性,我假设-我如何为我自己的定义Equality
创建这样的函数-是否也可以“烘焙”一些特殊的东西,以便重写将神奇地工作于Equal a b
?如果在repl中设置:set showimplicits
,您可以看到:t replace
的隐式参数:
replace : {a : Type} -> {x : a} -> {y : a} -> {P : a -> Type} ->
((=) {A = a} {B = a} x y) -> P x -> P y
p
没有什么特别之处,它只是一个隐式参数:一个谓词p
,它保存a
类型的值。这些隐式参数的大多数类型都可以推断,因此您的函数可能如下所示:
replaceEqual : {P : a -> Type} -> Equal x y -> P x -> P y
replaceEqual Reflexive prf = prf
但据我所知,你不能轻易地让自己的重写。但是,您可以使用语法规则美化您的方法:
syntax eqrewrite [a] "in" [b] = rewrite makeEquitable a in b;
plus_commutes_Z' : Equal m (plus m 0)
plus_commutes_Z' {m = Z} = Reflexive
plus_commutes_Z' {m = (S k)} =
let rec = plus_commutes_Z' {m=k}
in eqrewrite rec in Reflexive