22

I'm curious if anyone knows why the Scala library stops at 22 with its tuple type Tuple22?
Does the mysterious number 22 have a special hidden meaning?
Is this an internal joke of some kind?

Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
Ori
  • 12,800
  • 4
  • 33
  • 32
  • 20
    They felt that 23 would be a bit too much... ;) – aioobe Jun 05 '11 at 06:58
  • 2
    it's 22 for consistency with functions. And arity from 0-22 are 23 different functions and we all know what that means: http://en.wikipedia.org/wiki/23_(film) – Jens Schauder Jun 05 '11 at 17:20
  • 1
    possible duplicate of [why FunctionN(0-22) ProductN(1-22) TupleN(1-22)?](http://stackoverflow.com/questions/3618016/why-functionn0-22-productn1-22-tuplen1-22) – Daniel C. Sobral Jun 06 '11 at 19:21

4 Answers4

11

This question is not new, see http://scala-programming-language.1934581.n4.nabble.com/Why-tuples-only-to-22-td1945314.html or why FunctionN(0-22) ProductN(1-22) TupleN(1-22)?

AFAIK there is no "technical" explanation for it, they simply had to stop somewhere.

Community
  • 1
  • 1
Landei
  • 54,104
  • 13
  • 100
  • 195
3

Limit 22 is one of the dropped features of dotty (Scala 3) which now allows tuples of arbitrary arity:

The limits of 22 for... the maximal number of fields in tuple types have been dropped... tuples beyond Tuple22 are erased to a new trait scala.TupleXXL.

For example,

object Main {
  def main(args: Array[String]): Unit = {
    val tuple: Tuple = ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25")
    println(tuple.getClass)
    println(tuple.size)
  }
}

outputs

class scala.TupleXXL
25

For further examples see Add tests for the current tuple API #7633

Mario Galic
  • 47,285
  • 6
  • 56
  • 98
2

The case class limit has been lifted in 2.11 https://github.com/scala/scala/pull/2305

gdoubleod
  • 1,268
  • 3
  • 19
  • 33
  • In Scala 2.11.8: `error: too many elements for tuple: 24, allowed: 22 (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24) ^` – schmmd Aug 08 '16 at 17:55
2

I believe it has to do with difficulties in implementing a static type system while having variadic (arbitrary-argument) functions. I believe apply can be written in Scala (though not in Haskell, at least not elegantly).

ninjagecko
  • 88,546
  • 24
  • 137
  • 145