简体   繁体   English

如何比较Agda中的两套?

[英]How to compare two sets in Agda?

I want to write a function which take set as input and return true if it is top and false if it is bottom. 我想编写一个以set为输入的函数, return true if it is top and false if it is bottom. I have tried in this way.. 我试过这种方式..

isTop : Set → Bool
isTop x = if (x eq ⊤) then true
              else false

But i am not able to define eq correctly. 但我无法正确定义eq。 I tried as.. 我试过......

_eq_ : Set → Set → Bool
⊤ eq ⊥ = false

This is not working because when i check T eq T it is also returning false. 这不起作用,因为当我检查T eq T it is also returning false.

Please help me to write this eq function or any other ways to write isTop. 请帮我写这个eq函数或任何其他写isTop的方法。

It's impossible in Agda, but is not senseless in general. 这在阿格达是不可能的,但总的来说并非毫无意义

You could write something not very meaninigful: 你可以写一些不太吝啬的东西:

open import Data.Empty
open import Data.Unit
open import Data.Bool

data U : Set where
  bot top : U

⟦_⟧ : U -> Set
⟦ bot ⟧ = ⊥
⟦ top ⟧ = ⊤

record Is {α} {A : Set α} (x : A) : Set where

is : ∀ {α} {A : Set α} -> (x : A) -> Is x
is _ = _

isTop : ∀ {u} -> Is ⟦ u ⟧ -> Bool
isTop {bot} _ = false
isTop {top} _ = true

open import Relation.Binary.PropositionalEquality

test-bot : isTop (is ⊥) ≡ false
test-bot = refl

test-top : isTop (is ⊤) ≡ true
test-top = refl

u can be inferred from Is ⟦ u ⟧ , because ⟦_⟧ is constructor headed . u可以从Is ⟦ u ⟧推断,因为⟦_⟧构造者的头 Is is a singleton, so it allows to lift values to the type level. Is是单例,因此它允许将值提升到类型级别。 You can find an example of using here . 你可以在这里找到一个使用的例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM