简体   繁体   English

Agda中有哪些大小的类型?

[英]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的文章,但由于以下几点未能继续:

  1. Why are data types generic over their size? 为什么数据类型超出其大小? As far as I know the size is the depth of the tree of induction. 据我所知,大小是感应树的深度。
  2. Why are data types covariant over their size, ie i <= j -> T_i <= T_j ? 为什么数据类型在其大小上是协变的,即i <= j - > T_i <= T_j?
  3. What do the > and # patterns mean? >#模式意味着什么?
  1. The idea is that a sized type is just a family of types indexed by sizes, which are essentially ordinals. 这个想法是一个大小的类型只是一个由大小索引的类型系列,它们基本上是序数。 When defining an inductive type as 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本质上是尺寸为iS元素。 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) . 我觉得奇怪的是为什么SNatzero : (i : Size) -> SNat ($ i)定义zero : (i : Size) -> SNat ($ i)而不是zero : (i : Size) -> SNat ($ 0)
  2. For sized inductive types this makes sense, as T_i is the type of elements of T with size less than i, so that if i ≤ j then T_i ≤ T_j; 对于大小的电感类型,这是有意义的,因为T_i是尺寸小于 i的T的元素类型,因此如果i≤j则T_i≤T_j; constructors must increase the size in recursive calls. 构造函数必须增加递归调用的大小。
  3. 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.

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