AGDA:如何告诉类型系统两种类型相等?
说我的类型依赖于NAT
data MyType : (i : ℕ) → Set where
cons : (i : ℕ) → MyType i
和一个功能:
combine : {i₁ i₂ : ℕ} → MyType i₁ → MyType i₂ → MyType (i₁ ⊔ i₂)
现在我正在尝试编写一个功能:
create-combined : (i : ℕ) → MyType i
create-combined i = combine {i} {i} (cons i) (cons i)
不幸的是,我收到错误消息:
i ⊔ i != i of type ℕ
when checking that the inferred type of an application
MyType (i ⊔ i)
matches the expected type
MyType i
我知道我可以证明i⊔i≡i。 ''知道如何将该证明提供给类型系统以解决此问题。
我该如何汇编?
Say I have type dependent on Nat
data MyType : (i : ℕ) → Set where
cons : (i : ℕ) → MyType i
and a function:
combine : {i₁ i₂ : ℕ} → MyType i₁ → MyType i₂ → MyType (i₁ ⊔ i₂)
Now I'm trying to write a function:
create-combined : (i : ℕ) → MyType i
create-combined i = combine {i} {i} (cons i) (cons i)
Unfortunately, I get the error message:
i ⊔ i != i of type ℕ
when checking that the inferred type of an application
MyType (i ⊔ i)
matches the expected type
MyType i
I know I can prove i ⊔ i ≡ i
, but I don't know how to give that proof to the type system in order to get this to resolve.
How do I get this to compile?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从
relation.binary.binary.propositionalequality
中使用替代
。给它:
i⊔i
组合{i} {i}(cons i)(cons i)
,或者您可以在证明上也可以使用
重写
关键字,通常是优选的。这是对向量串联应用的两种可能性的(人为)示例:
You can use
subst
fromRelation.Binary.PropositionalEquality
.You give it:
i ⊔ i ≡ i
MyType
combine {i} {i} (cons i) (cons i)
Or you can use the
rewrite
keyword as well on your proof, which is usually to be preferred.Here is an (artificial) example of both possibilities applied on vector concatenation: