[英]How to compare two sets in Agda?
我想编写一个以set为输入的函数, return true if it is top and false if it is bottom.
我试过这种方式..
isTop : Set → Bool
isTop x = if (x eq ⊤) then true
else false
但我无法正确定义eq。 我试过......
_eq_ : Set → Set → Bool
⊤ eq ⊥ = false
这不起作用,因为当我检查T eq T it is also returning false.
请帮我写这个eq函数或任何其他写isTop的方法。
这在阿格达是不可能的,但总的来说并非毫无意义 。
你可以写一些不太吝啬的东西:
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
可以从Is ⟦ u ⟧
推断,因为⟦_⟧
是构造者的头 。 Is
是单例,因此它允许将值提升到类型级别。 你可以在这里找到一个使用的例子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.