Tuples
Tuples allow for the definition of a set of types, without having to define an explicit struct for it. These do not have any associated ID, meaning the order of declaration matters, and any modification to the type definition is generally incompatible.
The minimum amount of types in a tuple are 2 and the maximum are 12. Reasons for this choice are:
- A tuple with 0 types is empty and can’t carry any data.
- Having only 1 type is equivalent to the contained type itself and is redundant.
- Up to 12 types seems arbitrary, but having more than 3 or 4 types often calls for defining an explicit struct with field names for better clarity.
Schema
Section titled “Schema”In the schema, tuples are declared with parenthesis ( and ), each type separated by a comma ,, forming a definition like (T1, T2, TN...).
struct Sample { size: (u32, u32) @1,}Languages
Section titled “Languages”struct Sample { size: (u32, u32),}type Tuple2[T1 any, T2 any] struct { F1 T1 F2 T2}
/*type Tuple3[T1 any, T2 any, T3 any] struct { F1 T1 F2 T2 F2 T3}
...and so on...*/
type Sample struct { Size Tuple2[uint32, uint32]}data class Tuple2<T1, T2>( val f1: T1, val f2: T2,)
/*data class Tuple3<T1, T2, T3>( val f1: T1, val f2: T2, val f3: T3)
...and so on...*/
data class Sample( val size: Tuple2<UInt, UInt>,)class Sample { size: [number, number];
constructor(size: [number, number]) { this.size = size; }}@dataclassclass Sample: size: tuple[int, int]In Rust we have tuples and they look the same as in the schema, minus the ID.
There is no native support for tuples. Thus, types for tuples should be provided as part of the encompassing library, for up to N types.
Kotlin
Section titled “Kotlin”Again, no native support for tuples. The Map.Entry interface exists, but seems not to be meant as tuple replacement. Therefore, generic types should be provided together with the library, for up to N types.
TypeScript
Section titled “TypeScript”Typescript has support for tuples, defined as [T1, T2, TN...].
Python
Section titled “Python”Python has support for tuples, defined as tuple[T1, T2, TN...].