What is difference between tuples and records?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Both are product types which let you build types from multiple simpler types. Some languages treat tuples as a kind of record.
Definitions
A tuple is an ordered group of elements, like (10, 25).
A record is typically a group of named elements like
{ "x": 10, "y": 25 }where the value has two fields labelledxandyand the value of fieldxis10.Etymology
The word “tuple” comes from the common “-tuple” suffix on “quintuple”, “sextuple”, “septuple”, “octuple” which mean groups of 5, 6, 7, and 8 respectively.
The word “record” comes from data tables. You can think of all possible tuples with
xandyfields as a table where columns correspond to fields and rows collect all the fields for a particular record instance.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.