Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Idris 为我自己的平等使用重写?_Idris - Fatal编程技术网

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