[英]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.