Idris是否具有与Agda相同的功能

时间:2014-12-03 15:55:27

标签: list equality agda idris

Agda使用以下运算符来显示集合之间的反转:

_↔_ : ∀ {f t} → Set f → Set t → Set _

伊德里斯是否有同等效力?我正在尝试在列表上定义包等号

data Elem : a -> List a -> Type where
  Here  : {xs : List a} -> Elem x (x :: xs)
  There : {xs : List a} -> Elem x xs -> Elem x (y :: xs)

(~~) : List a -> List a -> Type
xs ~~ ys {a} = Elem a xs <-> Elem a ys

这样,当l1 ~~ l2l1按任意顺序具有相同的元素时,我们就可以构建l2

Agda definition of 似乎非常复杂,我不确定Idris标准库中是否有相同的内容。

1 个答案:

答案 0 :(得分:4)

Agda&#39; 背后的基本思想是将两个函数打包为两个往返的证明,这在Idris中也很容易做到:

infix 7 ~~
data (~~) : Type -> Type -> Type where
  MkIso : {A : Type} -> {B : Type} ->
          (to : A -> B) -> (from : B -> A) ->
          (fromTo : (x : A) -> from (to x) = x) ->
          (toFrom : (y : B) -> to (from y) = y) ->
          A ~~ B

您可以像以下最小例子一样使用它:

notNot : Bool ~~ Bool
notNot = MkIso not not prf prf
  where
    prf : (x : Bool) -> not (not x) = x
    prf True = Refl
    prf False = Refl

Agda版本更复杂的原因是因为它也是对平等选择的参数化,所以它不必是命题的(这是最严格/最好的)。将~~上面的=的Idris定义从PA : A -> A -> Type参数化为任意PB : B -> B -> Type和{{1}}留给读者。

相关问题