[英]What are sized types in Agda?
What are sized types in Agda? Agda中有哪些大小的类型? I've tried to read the paper about MiniAgda , but failed to proceed due to the following points: 我试图阅读有关MiniAgda的文章,但由于以下几点未能继续:
>
and #
patterns mean? >
和#
模式意味着什么? sized data
, the compiler checks that the result is a type with the correct size, so that, for example, succ
in SNat
increases the size in 1. That way, for a sized type S
(i : Size) -> S i
is essentially an element of S
with size i
. 当将归纳类型定义为sized data
,编译器会检查结果是否是具有正确大小的类型,例如, SNat
succ
SNat
增加1的大小。这样,对于大小类型S
(i : Size) -> S i
本质上是尺寸为i
的S
元素。 What looks weird to me is why the definition of zero for SNat
is zero : (i : Size) -> SNat ($ i)
instead of something like zero : (i : Size) -> SNat ($ 0)
. 我觉得奇怪的是为什么SNat
的zero : (i : Size) -> SNat ($ i)
定义zero : (i : Size) -> SNat ($ i)
而不是zero : (i : Size) -> SNat ($ 0)
。 As explained in section 2.3, #
is equivalent to T_∞, the type of elements of T with no known size bound; 如2.3节所述, #
相当于T_∞,T的元素类型没有已知的大小限制; this is a top element for the T_i's in the subtyping preorder. 这是子类型预订中T_i的顶级元素。 The pattern (i > j) is used to bind a size j while keeping the information that j < i. 模式(i> j)用于绑定大小j,同时保持j <i的信息。 The example in the paper for minus makes this clear: 文章中关于减号的例子清楚地说明了这一点:
fun minus : [i : Size] -> SNat i -> SNat # -> SNat i { minus i (zero (i > j)) y = zero j ; minus ix (zero .#) = x ; minus i (succ (i > j) x) (succ .# y) = minus jxy }
First the signature means that substracting any number ( SNat #
is a number with no size bound information) from a number of size at most i (that's what SNat i
means) returns a number of size at most i; 首先,签名意味着减去任意数量( SNat #
是一个没有大小限制信息的数字)来自多个大小的数量i(这就是SNat i
所说的SNat i
)最多返回一个大小的数量i; and for the >
pattern, in the last line we use it to match a number of size at most j, and the recursive call type checks because of subtyping: SNat j ≤ SNat i
. 对于>
模式,在最后一行,我们使用它来匹配最多j的数量,并且由于子类型,递归调用类型检查: SNat j ≤ SNat i
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.