元组vs记录 [英] tuples vs records

查看:374
本文介绍了元组vs记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

元组和记录之间有什么区别?

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 的字段, code> 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.

tuple一词来自五元组,六元组,七分之一,八元组中常见的元组后缀,其意思是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.

单词record来自数据表。您可以将 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.

这篇关于元组vs记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆