Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the limit (if any) to the tuple cardinality in Swift?

Tags:

swift

tuples

Each tuple cardinality is represented by its own type in swift (as in any other strongly-typed programming language I'm aware of), so we have

($T1, $T2)
($T1, $T2, $T3)
...

Since we have several different types, one per cardinality, they need to be finite.

In Scala we have up to Tuple22, in Haskell the current limit should be 64.

What's the limit (if any) in swift? Also, are the types implementations generated by the compiler or is there an explicit implementation I couldn't find?

like image 947
Gabriele Petronella Avatar asked Jun 26 '14 14:06

Gabriele Petronella


People also ask

Are tuples immutable in Swift?

@greenoldman as stated in the Swift guide, tuples are compound data types. Therefore, defining it as let makes it and its "members" immutable.

Can tuples have different data types Swift?

You can create tuples from as many values as you want and from any number of different data types.

What is the tuple in Swift?

In Swift, a tuple is a group of different values. And, each value inside a tuple can be of different data types.

Is tuple ordered in Swift?

You use tuples in Swift to make ordered, comma-separated lists of values.


1 Answers

In the current version of Xcode 6 Beta, compilation fails with tuples of arity larger than 1948 (the swift executable exits with code 254; there isn't a specific warning or error).

like image 162
Jean-Philippe Pellet Avatar answered Nov 03 '22 03:11

Jean-Philippe Pellet