元组与记录 [英] tuples vs records
问题描述
元组和记录有什么区别?
What is difference between tuples and records?
推荐答案
两者都是产品类型它允许您从多个更简单的类型构建类型.有些语言将元组视为一种记录.
Both are product types which let you build types from multiple simpler types. Some languages treat tuples as a kind of record.
元组是一组有序的元素,例如 (10, 25).
A tuple is an ordered group of elements, like (10, 25).
一条记录通常是一组命名元素,例如 { "x": 10, "y": 25 }
其中的值有两个标记为 x
和 y
,字段x
的值为10
.
A record is typically a group of named elements like { "x": 10, "y": 25 }
where the value has two fields labelled x
and y
and the value of field x
is 10
.
元组"一词来自五元组"、六元组"、七元组"、八元组"的常见-元组"后缀,分别表示 5、6、7 和 8 个组.
The word "tuple" comes from the common "-tuple" suffix on "quintuple", "sextuple", "septuple", "octuple" which mean groups of 5, 6, 7, and 8 respectively.
记录"一词来自数据表.您可以将具有 x
和 y
字段的所有可能的元组视为一个表,其中列对应于字段,行收集特定记录实例的所有字段.
The word "record" comes from data tables. You can think of all possible tuples with x
and y
fields as a table where columns correspond to fields and rows collect all the fields for a particular record instance.
value address field x field y
0xABCD 10 25
0x1234 42 "xyz"
产品类型的等效性
您可以将元组视为一种记录,其中元组中元素的索引是其在等效记录中的名称,因此 (10, 25)
是 { "0":10,1":25 }
.我相信标准 ML 和相关语言使用记录作为类型连词(代数数据类型 提供类型分离)并以这种方式将元组视为一种记录.
Equivalence of product types
You can treat a tuple as a kind of record, where the index of an element in a tuple is its name within the equivalent record, so (10, 25)
is { "0": 10, "1": 25 }
. I believe Standard ML and related languages use records as the basic unit of type conjunction (algebraic data types provide type disjunction) and treat tuples as a kind of record in this way.
这篇关于元组与记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!