16

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?

Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
  • I think the WWDC video says that there isn't a limit. I'll try to get an exact quote. – Aaron Brager Jun 26 '14 at 14:20
  • I don't think there is something mentioned in apple Swift book about tuple limit. The one thing I remember is that tuples are not suited to the creation of complex data structures in that case you should use class or structure. – Greg Jun 26 '14 at 14:20
  • Actually it's not true that you have a different type for each cardinality. You have a different type for each ... tuple type. A tuple of two `Int`s has a different type than a tuple of two `Double`s, even if they have the same cardinality. A tuple type is in fact an extension of a product type to higher cardinalities in the same sense that a tuple is an extension of an ordered pair to higher cardinalities. – Analog File Jun 26 '14 at 16:53
  • @AnalogFile I'll do here the same observation I did in another answer: `Tuple2` is a polymorphic type. `Tuple2` is a concrete type. Still types though. – Gabriele Petronella Jun 26 '14 at 23:01
  • @GabrielePetronella Nope. I replied in more details to your other comment: http://stackoverflow.com/questions/24429455/underlying-type-for-tuple-in-swift/24431787#comment37820394_24431787 – Analog File Jun 26 '14 at 23:57
  • Ok, `Tuple2` is a polymorphic type, `Tuple2` is a concrete type. My point still holds: you have a (polymorphic) type for each tuple cardinality. – Gabriele Petronella Jun 27 '14 at 00:02

1 Answers1

11

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).

Jean-Philippe Pellet
  • 59,296
  • 21
  • 173
  • 234